android - ListView Not Clickable or LongClickable -
i have custom listview can't manage click , longclick on that
xml of listactivity :
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:descendantfocusability="blocksdescendants" > <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@id/activity_main_l2" android:layout_margintop="44dp" android:layout_gravity="bottom" android:gravity="bottom"> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/main" android:layout_gravity="center" android:gravity="bottom" android:visibility="visible" android:id="@id/activity_main_search_layer"> <edittext android:id="@id/activity_main_search_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:background="@drawable/message_field" android:hint="@string/search_hint" android:textcolor="@color/textfieldcolor" android:layout_gravity="center" android:maxlines="8" android:paddingleft="10dp" android:paddingtop="5dp" android:paddingright="10dp" android:paddingbottom="10dp" android:textsize="14dp" android:singleline="true"/> </linearlayout> <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:divider="#00000000" android:background="#ffffff" android:fastscrollalwaysvisible="true" android:fastscrollenabled="true" android:listselector="#00000000" android:focusable="true" android:focusableintouchmode="true" android:clickable="true" android:longclickable="true"/> </linearlayout> <include layout="@layout/header1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/include"/> <include layout="@layout/draver_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/include1"/> </framelayout> and xml of listrow :
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="70dp" android:background="#fafafa" android:gravity="end" android:orientation="horizontal" android:id="@id/list_row_rl" android:padding="5dp" android:focusable="false" android:focusableintouchmode="false" android:descendantfocusability="blocksdescendants" > <linearlayout android:orientation="vertical" android:layout_width="70dp" android:layout_height="fill_parent" android:layout_weight="0" android:focusable="false" android:focusableintouchmode="false"> <framelayout android:layout_width="70dp" android:layout_height="fill_parent" android:foregroundgravity="center" android:layout_gravity="center" android:focusable="false" android:focusableintouchmode="false"> <framelayout android:id="@+id/thumbnail" android:layout_width="60dp" android:layout_height="wrap_content" android:layout_marginright="5dip" android:padding="3dp" android:layout_gravity="center" android:foregroundgravity="center" android:focusable="false" android:focusableintouchmode="false"> <quickcontactbadge android:id="@+id/quickcontactbadge1" android:layout_width="52dp" android:layout_height="52dp" android:scaletype="fitcenter" android:layout_gravity="center"/> <linearlayout android:orientation="vertical" android:layout_width="52dp" android:layout_height="52dp" android:background="@drawable/round_frame" android:layout_gravity="center" android:gravity="center" android:focusable="false" android:focusableintouchmode="false"> </linearlayout> </framelayout> <linearlayout android:orientation="vertical" android:layout_width="20dp" android:layout_height="20dp" android:background="@drawable/rounded_counter" android:layout_gravity="bottom|left" android:layout_marginleft="4dp" android:layout_marginbottom="10dp" android:id="@id/list_row_number_of_new_sms_layer" android:visibility="invisible" android:focusable="false" android:focusableintouchmode="false"> <textview android:id="@+id/numberofsms" android:layout_width="40dp" android:layout_height="wrap_content" android:text="420" android:textcolor="#ffffff" android:textsize="10dp" android:textisselectable="false" android:singleline="true" android:gravity="center" android:layout_gravity="center" android:textcolorhighlight="#000000" android:autotext="false" android:layout_marginleft="4dp" android:layout_margintop="3dp" android:layout_marginright="5dp" android:focusable="false" android:focusableintouchmode="false"/> </linearlayout> </framelayout> </linearlayout> <framelayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <button android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@id/list_row_click_button" android:background="#fafafa" android:focusable="false" android:focusableintouchmode="false"/> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@id/list_row_click_layer"> <linearlayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:focusable="false" android:focusableintouchmode="false"> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="68dp" android:id="@id/list_row_l1" android:gravity="right|top" android:layout_gravity="left|top" android:focusable="false" android:focusableintouchmode="false"> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" android:layout_gravity="center|left|top" android:layout_marginright="5dp" android:gravity="left|top" android:focusable="false" android:focusableintouchmode="false"> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="35dp" android:layout_gravity="left|top" android:gravity="left|top" android:focusable="false" android:focusableintouchmode="false"> <textview android:id="@+id/contactname" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0.60" android:text="@string/contactname" android:textcolor="#666666" android:textsize="16dp" android:textstyle="bold" android:typeface="sans" android:textalignment="gravity" android:layout_gravity="left|top" android:layout_marginright="5dp" android:gravity="left|top" android:phonenumber="true" android:layout_marginleft="5dp" android:maxheight="40dp" android:singleline="true" android:focusable="false" android:focusableintouchmode="false" /> <textview android:layout_width="wrap_content" android:layout_height="fill_parent" android:id="@id/list_row_count" android:singleline="true" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:layout_gravity="left|top" android:gravity="left|top" android:textsize="16dp" android:focusable="false" android:focusableintouchmode="false"/> </linearlayout> <textview android:id="@+id/lastsms" android:layout_width="fill_parent" android:layout_height="20dp" android:text="سلام امروز روز خوبی است." android:textcolor="#aeaeae" android:textsize="12dp" android:singleline="true" android:layout_marginright="5dp" android:phonenumber="false" android:layout_marginleft="5dp" android:layout_marginbottom="2dp" android:linksclickable="true" android:autolink="web" android:layout_gravity="center_vertical|left" android:gravity="center|left" android:focusable="false" android:focusableintouchmode="false" /> </linearlayout> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="2dp" android:background="#f34323" android:focusable="false" android:focusableintouchmode="false"> </linearlayout> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="70dp" android:layout_height="fill_parent" android:layout_weight="0" android:layout_gravity="top" android:gravity="top" android:focusable="false" android:focusableintouchmode="false"> <linearlayout android:layout_width="fill_parent" android:layout_height="68dp" android:foregroundgravity="left|top" android:orientation="vertical" android:layout_gravity="center|top" android:gravity="center|top" android:focusable="false" android:focusableintouchmode="false"> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/list_row_draft_text" android:id="@+id/list_row_draft_textview" android:layout_gravity="right" android:textsize="8dp" android:textcolor="#ff00ac" android:visibility="invisible" android:focusable="false" android:focusableintouchmode="false"/> <textview android:id="@+id/date" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="5:45" android:textcolor="#aeaeae" android:textsize="11dp" android:gravity="center_vertical" android:layout_gravity="right" android:layout_marginbottom="10dp" android:focusable="false" android:focusableintouchmode="false"/> </linearlayout> <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="2dp" android:background="#f34323" android:id="@+id/linearlayout" android:focusable="false" android:focusableintouchmode="false"/> </linearlayout> </linearlayout> </framelayout> </linearlayout> and in listactivity :
list.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() { public boolean onitemlongclick(adapterview parent, view view, int position, long id) { code... } }); list.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview<?> a, view v, int position, long id) { code... } }); but non of these listener click or longclick
longclock on 1 of textview(android:id="@+id/contactname") work
the adapter :
public class adapter extends arrayadapter<boxinfoobject> implements filterable { public adapter(context c, int resource, int layout, arraylist<boxinfoobject> d) { super(c, resource); this.c = c; morigionalvalues = new arraylist<boxinfoobject>(d); mobjects = new arraylist<boxinfoobject>(d); } private static class viewholder { public linearlayout l0; public textview name, last, numberof, date, draft, numberofnew; public quickcontactbadge badge; public linearlayout l1, l2; public int position; public listview list; } public void add(boxinfoobject object) { morigionalvalues.add(object); this.notifydatasetchanged(); } public filter getfilter() { if (mfilter == null) { mfilter = new customfilter(); } return mfilter; } public int getcount() { return mobjects.size(); } public boxinfoobject getitem(int position) { return mobjects.get(position); } public long getitemid(int position) { return position; } public view getview(int position2, view convertview, viewgroup parent) { view vi = convertview; viewholder holder; if (convertview == null) { holder = new viewholder(); vi = layoutinflater.from(c).inflate(r.layout.list_row, null, false); holder.l1 = (linearlayout) vi.findviewbyid(r.id.list_row_l1); holder.l0 = (linearlayout) vi.findviewbyid(r.id.list_row_rl); holder.date = (textview) vi.findviewbyid(r.id.date); holder.badge = (quickcontactbadge) vi .findviewbyid(r.id.quickcontactbadge1); // thumb image holder.list = (listview) parent.findviewbyid(r.id.list); ,... vi.settag(holder); } else holder = (viewholder) vi.gettag(); holder.position = position2; box = mobjects.get(holder.position); int apilevel = android.os.build.version.sdk_int; if (apilevel > 11) new load(holder, position2) .executeonexecutor(asynctask.thread_pool_executor, null); else new load(holder, position2).execute(); return vi; } private class load extends asynctask<viewholder, void, void> { private final int p; private viewholder h; private string holder_name_string; private int holder_l2_visible; private string holder_numberofnew_string; private boxinfoobject box; private quickcontacthelper qch; private quickcontactbadge badge; private string holder_date; private inboxquickaction quickaction; private string holder_text; public load(viewholder holder, int p) { this.h = holder; this.p = p; } @override protected void onpreexecute() { } @override protected void onpostexecute(void avoid) { if (h.position == p) { h.date.settext(holder_date); if (holder_numberofnew_string != null) if (holder_numberofnew_string.length() > 0) h.l2.setvisibility(holder_l2_visible); else h.l2.setvisibility(view.gone); else h.l2.setvisibility(view.gone); h.numberofnew.settext(holder_numberofnew_string); notifydatasetchanged(); } } @override protected void doinbackground(viewholder... arg0) { try { h.date.settypeface(h.font); h.numberof.settypeface(h.font); h.name.settypeface(h.font); box = mobjects.get(p); holder_text = box.getsmses().get(box.getsmses().size() - 1).getmessage(); holder_date = makebox.stringdate(c, box.get().get(box.get().size() - 1).getmydate(), h); if (box.getpns().size() == 1) qch = new quickcontacthelper(c, box.getpns().get(0), box.getopns().get(0)); else qch = new quickcontacthelper(c); try { qch.badgeimage2(h.badge, false); badge = qch.getbadge(); badge.setmode(contactscontract.quickcontact.mode_small); } catch (exception e) { } if (box.getpns().size() == 1) { holder_name_string = qch.getname(); if (holder_name_string == null) { badge.setimageresource(r.drawable.unknown); } else { if (qch.holder.tid == null || qch.holder.tid == 0) badge.setimageresource(r.drawable.personal); } } else { badge.setimageresource(r.drawable.multiplus); } int nons = box.getnnew(); if (nons > 0) { holder_l2_visible = view.visible; holder_numberofnewsms_string = nons + ""; } else { holder_l2_visible = view.gone; holder_numberofnewsms_string = ""; } } catch (exception e) { } return null; } } any suggestion ?
Comments
Post a Comment