i've got new list of things needs clicked 1 isn't working. onlistitemclick never called. have 1 in app has been working expected , can't figure out difference is. occurs me maybe there's conflict since both using provided @id/android:list they're in different activities , haven't found other people complaining same problem i'm not sure.
here bunch of code. appreciate suggestions.
working:
@override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); // item clicked v_projectinvestigatorsitecontact project = (v_projectinvestigatorsitecontact) this.getlistadapter().getitem( position); intent myintent = new intent(this, details.class); myintent.putextra(res.getstring(r.string.project), project); startactivity(myintent); }// onlistitemclick
not working:
@override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); // item clicked final v_sitepeople vsitepeople = (v_sitepeople) this.getlistadapter().getitem( position); alertdialog.builder builder = new alertdialog.builder(share.this); builder.settitle(res.getstring(r.string.forgot_password_check_dialog_title)) .setmessage(res.getstring(r.string.share_check_dialog_text)) .setpositivebutton(res.getstring(r.string.send), new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { sendshareemail(vsitepeople); } }).setnegativebutton(res.getstring(r.string.cancel), new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // cancelled, nothing } }); alertdialog msgbox = builder.create(); msgbox.show(); }// onlistitemclick
working xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffffff" android:orientation="vertical" > <!-- dummy item prevent edittext gaining focus on activity start --> <linearlayout android:layout_width="0px" android:layout_height="0px" android:focusable="true" android:focusableintouchmode="true" /> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/title_background" > <imageview android:id="@+id/logo" android:layout_width="30dp" android:layout_height="30dp" android:layout_centervertical="true" android:layout_marginleft="5dp" android:scaletype="centercrop" android:src="@drawable/ic_logo" > </imageview> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_torightof="@+id/logo" android:gravity="center" android:paddingbottom="5dp" android:paddingleft="50dp" android:paddingright="60dp" android:paddingtop="5dp" android:text="@string/app_header" android:textcolor="#ffffffff" android:textsize="15sp" android:textstyle="bold" /> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/search_gradient" > <imageview android:id="@+id/searchboxicon" android:layout_width="38dp" android:layout_height="38dp" android:layout_centervertical="true" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:scaletype="centercrop" android:src="@drawable/action_search" > </imageview> <edittext android:id="@+id/searchbox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centervertical="@+id/searchboxicon" android:layout_marginright="8dp" android:layout_margintop="4dp" android:layout_torightof="@+id/searchboxicon" android:background="@drawable/search_box" android:hint="@string/search_hint" android:inputtype="text" android:maxlines="1" android:minheight="30sp" android:paddingbottom="2dp" android:paddingleft="25sp" android:paddingtop="2dp" android:textcolor="#ff000000" /> </relativelayout> <listview android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/divider_gray" android:cachecolorhint="#00000000" android:divider="@color/divider_gray" android:dividerheight="1dp" android:footerdividersenabled="false" android:headerdividersenabled="false" /> <textview android:id="@+id/android:empty" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="@string/loading" android:textcolor="@color/loading_gray" android:textsize="20sp" /> </linearlayout>
not working xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffffff" android:orientation="vertical" > <!-- dummy item prevent edittext gaining focus on activity start --> <linearlayout android:layout_width="0px" android:layout_height="0px" android:focusable="true" android:focusableintouchmode="true" /> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/title_background" > <imageview android:id="@+id/logo" android:layout_width="30dp" android:layout_height="30dp" android:layout_centervertical="true" android:layout_marginleft="5dp" android:scaletype="centercrop" android:src="@drawable/ic_logo" > </imageview> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_torightof="@+id/logo" android:gravity="center" android:paddingbottom="5dp" android:paddingleft="50dp" android:paddingright="60dp" android:paddingtop="5dp" android:text="@string/share_header" android:textcolor="#ffffffff" android:textsize="15sp" android:textstyle="bold" /> </relativelayout> <listview android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/divider_gray" android:cachecolorhint="#00000000" android:divider="@color/divider_gray" android:dividerheight="1dp" android:footerdividersenabled="false" android:headerdividersenabled="false" /> <textview android:id="@+id/android:empty" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="@string/loading" android:textcolor="@color/loading_gray" android:textsize="20sp" /> </linearlayout>
here more on how broken 1 works, in case want more code.
not working row xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?android:attr/listpreferreditemheight" android:layout_weight="1" android:baselinealigned="false" android:orientation="vertical" android:padding="6dp" android:background="#ffffffff" android:layout_margin="10dp" > <textview android:id="@+id/toptext" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toleftof="@id/moreinfo" android:gravity="center_vertical" android:minheight="20sp" android:textcolor="#ff000000" android:textstyle="bold" /> </relativelayout>
not working view adapter
@override public view getview(int position, view convertview, viewgroup parent) { viewholder holder = null; if (convertview == null) { holder = new viewholder(); layoutinflater vi = (layoutinflater) getcontext().getsystemservice(context.layout_inflater_service); convertview = vi.inflate(r.layout.share_row, null); convertview.settag(holder); }// if else { holder = (viewholder) convertview.gettag(); } v_sitepeople = items.get(position); if (i != null) { textview toptext = (textview) convertview.findviewbyid(r.id.toptext); toptext.setgravity(gravity.center_vertical); toptext.setminheight(40); if (toptext != null) { if (i.siteperson != null) { if (i.persontitle != null) { toptext.settext(string.format(i.siteperson + ", " + i.persontitle)); } else { toptext.settext(i.siteperson); } }// if has protocolnumber else { if (i.nickname != null) { toptext.settext(i.nickname); } }// if not have protocolnumber }// if }// if return convertview; }// getview
thank help.
more code requested.
working setlistadapter:
public void updatedisplay(arraylist<v_projectinvestigatorsitecontact> vprojectinvestigatorsitecontactlist) { if (fulladapter != null) { if (fulladapter.isempty()) { fulladapter = new projectadapter(this, r.layout.row, vprojectinvestigatorsitecontactlist); fulladapter = reorder(fulladapter); setlistadapter(fulladapter); } else { filteredadapter = new projectadapter(this, r.layout.row, vprojectinvestigatorsitecontactlist); filteredadapter = reorder(filteredadapter); setlistadapter(filteredadapter); } } else { fulladapter = new projectadapter(this, r.layout.row, vprojectinvestigatorsitecontactlist); fulladapter = reorder(fulladapter); setlistadapter(fulladapter); } }// updatedisplay
working list setup:
private class downloadprojectstask extends asynctask<string, void, arraylist<v_projectinvestigatorsitecontact>> { @override protected arraylist<v_projectinvestigatorsitecontact> doinbackground(string... urls) { return projectshelper.parseprojects(urls, currentstudies.this); }// doinbackground @override protected void onpostexecute(arraylist<v_projectinvestigatorsitecontact> vprojectinvestigatorsitecontactlist) { updatedisplay(vprojectinvestigatorsitecontactlist); }// onpostexecute }// downloadprojectstask
working adapter:
public class projectadapter extends arrayadapter { private arraylist items; private resources res;
public projectadapter(context context, int textviewresourceid, arraylist<v_projectinvestigatorsitecontact> items) { super(context, textviewresourceid, items); this.items = items; this.res = context.getresources(); }// projectadapater @override public int getcount() { return items.size(); } @override public v_projectinvestigatorsitecontact getitem(int position) { return items.get(position); } @override public long getitemid(int position) { return position; } @override public int getviewtypecount() { return 2; } @override public int getitemviewtype(int position) { if (items.get(position).projectid == null) { return 0; } else { return 1; } } @override public boolean isenabled(int position) { if (getitemviewtype(position) == 0) { return false; } return true; } @override public view getview(int position, view convertview, viewgroup parent) { viewholder holder = null; int type = getitemviewtype(position); if (convertview == null) { holder = new viewholder(); layoutinflater vi = (layoutinflater) getcontext().getsystemservice(context.layout_inflater_service); if (type == 0) { convertview = vi.inflate(r.layout.row_header, null); } else { convertview = vi.inflate(r.layout.row, null); } convertview.settag(holder); }// if else { holder = (viewholder) convertview.gettag(); } v_projectinvestigatorsitecontact = items.get(position); if (i != null) { textview toptext = (textview) convertview.findviewbyid(r.id.toptext); textview bottomtext = (textview) convertview.findviewbyid(r.id.bottomtext); if (toptext != null) { if (i.protocolnumber != null) { if (i.webindication != null) { toptext.settext(i.protocolnumber); bottomtext.settext(i.webindication); } else if (i.projectname != null) { toptext.settext(i.protocolnumber); bottomtext.settext(i.projectname); } }// if has protocolnumber else { if (i.webindication != null) { toptext.settext(i.webindication); toptext.setminheight(40); toptext.setgravity(gravity.center_vertical); } else if (i.projectname != null) { toptext.settext(i.projectname); toptext.setminheight(40); toptext.setgravity(gravity.center_vertical); } else { toptext.settext(i.siteid); toptext.setminheight(40); toptext.setgravity(gravity.center_vertical); } }// if not have protocolnumber }// if // coming logic if (i.projectstatusid != null) { if (i.projectstatusid.equals(res.getstring(r.string.feasibility_id))) { toptext.settextcolor(res.getcolor(r.color.coming_soon_gray)); bottomtext.settext("(coming soon)"); } else { toptext.settextcolor(color.black); } }//if if (bottomtext != null) { if (type == 0) { if (position == getcount() - 1 || getitemviewtype(position + 1) == 0) { bottomtext.setvisibility(view.visible); bottomtext.settext(res.getstring(r.string.no_studies)); bottomtext.setlayoutparams(new layoutparams(layoutparams.wrap_content, 0, (float) 1.0)); } else { bottomtext.setvisibility(view.gone); } }// header followed header, or end of list }// if //recenters row headers if (type == 0) { toptext.setgravity(gravity.center); } }// if return convertview; }// getview public static class viewholder { public textview textview; }
}// projectadapter
not working setlistadapter:
public void updatedisplay(arraylist<v_sitepeople> vsitepeoplesharelist) { adapter = new shareadapter(this, r.layout.share_row, vsitepeoplesharelist); setlistadapter(adapter); }// updatedisplay
not working list setup:
private class downloadsharetask extends asynctask<string, void, arraylist<v_sitepeople>> { @override protected arraylist<v_sitepeople> doinbackground(string... params) { return projectshelper.getsharepeople(params[0], share.this); }// doinbackground @override protected void onpostexecute(arraylist<v_sitepeople> vsitepeoplesharelist) { updatedisplay(vsitepeoplesharelist); }// onpostexecute }// downloadprojectstask
i figured out. didn't ever post relevant code, or i'm sure guys have spotted me.
i copied non working adapter working piece of code returns false if viewtype 0. , since second list has 1 type, disabled.
thank efforts. apologize didn't give correct code.
Comments
Post a Comment