android - ListView setOnItemClickListener Does Not Trigger -
click listener not working when click item.
in program first 2 arraylist updated using update(). list view sent other class make list view. clicking each item doesn't toast anything.
public class blockactivity extends activity { listview lv; arraylist<string> contactnumber= new arraylist<string>(); arraylist<string> contactname= new arraylist<string>(); public static sqlitedatabase database; sqlitedatabase mydb= null; customadapter adapter; arraylist<string> contactnum= new arraylist<string>(); arraylist<string> contactnam= new arraylist<string>(); public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); button pickcontact = (button) findviewbyid(r.id.button1); update(); lv=(listview) findviewbyid(r.id.listview1); adapter = new customadapter(this, contactnam, contactnum); lv.setadapter(adapter); lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { /*new alertdialog.builder(view.getcontext()) .setmessage("something here") .setnegativebutton("close", null).show();*/ toast.maketext(blockactivity.this, "item in position " + position + " clicked", toast.length_long).show(); } }); pickcontact.setonclicklistener(new onclicklistener() { . . .
main.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="add" /> <listview android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content" > </listview>
detail.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:focusableintouchmode="false" android:focusable="false"> <linearlayout android:layout_width="match_parent" android:layout_height="50dip" android:layout_weight="1" android:focusable="false" android:focusableintouchmode="false"> <button android:id="@+id/button2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="button"/> <textview android:id="@+id/one" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="name" android:textsize="20dip" android:layout_gravity="center" android:focusable="false" android:focusableintouchmode="false"/> <textview android:id="@+id/two" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="name" android:textsize="20dip" android:layout_gravity="center" android:focusable="false" android:focusableintouchmode="false"/> </linearlayout> <button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="2dip" android:background="#ff7f7f"/>
thats because of button
, add android:descendantfocusability="blocksdescendants"
in list item root layout
detail.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:descendantfocusability="blocksdescendants" > <linearlayout android:layout_width="match_parent" android:layout_height="50dip" android:layout_weight="1" android:focusable="false" android:focusableintouchmode="false"> <button android:id="@+id/button2" android:layout_width="0dp" android:layout_height="wrap_content" android:text="button"/> <textview android:id="@+id/one" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="name" android:textsize="20dip" android:layout_gravity="center"/> <textview android:id="@+id/two" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="name" android:textsize="20dip" android:layout_gravity="center"/> </linearlayout> <button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="2dip" android:background="#ff7f7f"/>
Comments
Post a Comment