i have listview custom adapter , list items containing textview(s) only. list items have onitemclick method set in oncreate callback method.
templateslistview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { log.d(debug_tag, "templateslistview onclick()"); //item selected cursor necessary data log.d(debug_tag, "listview count: " + templateslistview.getcount()); log.d(debug_tag, "messagescursor count: " + messagescursor.getcount()); if (position >= messagescursor.getcount()) { log.d(debug_tag, "unable access element " + position + ", not exist in messagescursor. cursor count: " + messagescursor.getcount()); } messagescursor.movetoposition(position); final string selecteditemname = messagescursor.getstring(1); alertdialog.builder builder = new alertdialog.builder(sendmessageactivity.this); builder.settitle(selecteditemname).setmessage("do want use template: "+selecteditemname+"?"); //use template onclick builder.setpositivebutton("use", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dlg, int x) { messageedittext.settext(selecteditemname); } }); //cancel onclick builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dlg, int x) { } }); builder.show(); } });
the listview in activity layout file defined as:
<listview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/templateslistview" android:layout_alignparentright="true" android:clickable="true" android:layout_alignparentend="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_below="@+id/sendbutton" />
the list item defined in separate layout file as:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancemedium" android:text="medium text" android:id="@+id/name_textview" />
the onclick method called correctly when run app on android 4.4.4, when run on android 5.1.1 not called @ all.
the list item layout has been created v21+ separately, please find code below:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="medium text" android:id="@+id/name_textview" android:singleline="true" android:textcolor="@color/foreground_material_light" android:theme="@android:style/widget.material.light.button.borderless" />
do guys know should change make work on api level 21+ ? matter of xml file (attributes?) or should change implementation? cheers!
solved: think additional layout file confusing application. named same original one, (v21) added @ end of it. after removing second file works fine.