Satyam Rathore

Satyam Rathore

  • NA
  • 1
  • 811

Custom Lisview with Button in android

Jan 27 2016 5:15 AM
hello friends,
i am new person in this community and posting first question with hope that someone will help me..... 
 i am begginner in android and  learning how make a custom listview but in this task i am facing problems it is not workin giving error of "unfortunately app has stopped"  so please help me i am posting my code below so please explain me what mistakes i am making......
 
 MainActivty code(Doctor_List)- 

public class Doctor_List extends Activity {
String[] name={"Dr.Anil kohli" };
String[] Available={"Available"};
String[] clinic={"Dr. Soni's Dental clinic and UltraSound Centre"};
String[] Address={"Lajpat nagar"};
String[] Numberlike={"337"};
String[] Experience={"40 Yrs exp."};
String[] fees={"Fees"};
String [] Review={"13 Reviews"};
Integer[] images={R.drawable.thumbsup2,R.drawable.dentist};

Button btn;
ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_doctor_list);
DoctorList_Adapter adapter = new DoctorList_Adapter(Doctor_List.this, name, Available, clinic, Address, Numberlike, Experience, fees, Review, images);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
}

}
Code of adapter class(DoctorList_Adapter)-
public class DoctorList_Adapter extends ArrayAdapter<String>{
Activity context;
String[] name;
String[] Available;
String[] clinic;
String[] Address;
String[] Numberlike;
String[] Experience;
String[] fees;
String[] Review;
Integer[] images;



public DoctorList_Adapter(Activity context, String[] Name, String[] available, String[] Clinic, String[] address, String[] numberlike, String[] experience, String[] Fees, String[] review, Integer[] Images ) {
super(context,R.layout.single_list_doctor_list,Name);
this.context=context;
this.name=Name;
this.Available=available;
this.clinic=Clinic;
this.Address=address;
this.Numberlike=numberlike;
this.Experience=experience;
this.fees=Fees;
this.Review=review;
this.images=Images;

}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
super.getView(position, convertView, parent);
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.single_list_doctor_list, null, true);
TextView Drname= (TextView) rowView.findViewById(R.id.Drname);
Drname.setText(name[position]);
TextView available_today= (TextView) rowView.findViewById(R.id.available);
available_today.setText(Available[position]);
TextView cclinic= (TextView) rowView.findViewById(R.id.clinic);
cclinic.setText(clinic[position]);
TextView Aaddress= (TextView) rowView.findViewById(R.id.Address);
Aaddress.setText(Address[position]);
TextView numberlike= (TextView) rowView.findViewById(R.id.numberlike);
numberlike.setText(Numberlike[position]);
TextView exp= (TextView) rowView.findViewById(R.id.exp);
exp.setText(Experience[position]);
TextView Dfee= (TextView) rowView.findViewById(R.id.fee);
Dfee.setText(fees[position]);
TextView rev= (TextView) rowView.findViewById(R.id.Review);
rev.setText(Review[position]);
ImageView imageview= (ImageView) rowView.findViewById(R.id.likethumbsup);
imageview.setImageResource(images[position]);
ImageView imageview1= (ImageView) rowView.findViewById(R.id.dentistimage);
imageview1.setImageResource(images[position]);
ImageView imageview2= (ImageView) rowView.findViewById(R.id.dentistimage1);
imageview2.setImageResource(images[position]);
ImageView imageview3= (ImageView) rowView.findViewById(R.id.dentistimage2);
imageview3.setImageResource(images[position]);
Button booknow= (Button) rowView.findViewById(R.id.button);
booknow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
return rowView;

}
}
single_list_doctor_list.xml code- 
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Doctor_List"
tools:showIn="@layout/activity_main_doctor_list"
android:background="@color/white"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Dr. Anil Kohli"
android:id="@+id/Drname"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Available Today"
android:textColor="@color/green"
android:id="@+id/available"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Dr. Soni's Dental clinic and UltraSound Centre"
android:id="@+id/clinic"
android:layout_below="@+id/Drname"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Lajpat Nagar"
android:id="@+id/Address"
android:layout_below="@+id/clinic"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/dentistimage"
android:layout_below="@+id/Address"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/dentist"/>

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/dentistimage1"
android:layout_alignTop="@+id/dentistimage"
android:layout_toRightOf="@+id/dentistimage"
android:layout_toEndOf="@+id/dentistimage"
android:src="@drawable/dentist"/>

<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/dentistimage2"
android:layout_below="@+id/Address"
android:layout_toRightOf="@+id/dentistimage1"
android:layout_toEndOf="@+id/dentistimage1"
android:src="@drawable/dentist"/>

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/likethumbsup"
android:src="@drawable/thumbsup2"
android:layout_marginRight="43dp"
android:layout_marginEnd="43dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="337"
android:id="@+id/numberlike"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="40 Yrs exp."
android:id="@+id/exp"
android:layout_below="@+id/dentistimage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />


<Button
android:layout_width="75dp"
android:layout_height="25dp"
android:text="BOOK"
android:id="@+id/button"
android:background="@color/orange"
android:layout_alignBottom="@+id/Review"
android:layout_alignLeft="@+id/likethumbsup"
android:layout_alignStart="@+id/likethumbsup"
android:focusable="false"

/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Fees"
android:id="@+id/fee"
android:layout_below="@+id/dentistimage2"
android:layout_toRightOf="@+id/Address"
android:layout_toEndOf="@+id/Address" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="13 Reviews"
android:id="@+id/Review"
android:layout_below="@+id/dentistimage2"
android:layout_toRightOf="@+id/dentistimage2"
android:layout_toEndOf="@+id/dentistimage2" />


</RelativeLayout>
activity_main_doctor_list.xml code-
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Doctor_List"
android:orientation="vertical"
android:id="@+id/LinearLayout"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list"
tools:listitem="@layout/single_list_doctor_list"


>

</ListView>


</LinearLayout>
  
 
 
 

Answers (2)