Custom List Fragment disabling clicks to element and enabling button clicks(Android Studio) -
i know similar questions not make them work. have list fragment includes item in array list , button next each element in array list. ultimate goal make program respond when user clicks button not manage detect clicks on screen. tried setting button's focusable false(suggested other questions) did not work. here code.
public class resultlistfragment extends listfragment { private list<string> listvalues, keyvalues; private string email, username; private arrayadapter<string> myadapter; private listview mylistview; private textview title; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_resultlist, container, false); return view; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); view v = getview(); mylistview = getlistview(); listvalues = new arraylist<string>(); myadapter = new arrayadapter<string>(getactivity().getapplicationcontext(), r.layout.fragment_rowlayout, r.id.mylisttext, cameraactivity.resultlist); setlistadapter(myadapter); myadapter.notifydatasetchanged(); } @override public void onlistitemclick(listview l, view v, final int position, long id) { super.onlistitemclick(l, v, position, id); log.d("blabla", "onlistitemclick: clicked : "+position); final string delete=cameraactivity.resultlist.get(position); alertdialog.builder builder = new alertdialog.builder(getactivity()); builder.setcancelable(true); builder.settitle("deletion"); builder.setmessage(delete + " delete it."); builder.setpositivebutton("onayla", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { toast.maketext(getactivity().getapplicationcontext(), delete+ "has been deleted", toast.length_short).show(); cameraactivity.resultlist.remove(position); myadapter.notifydatasetchanged(); for(string st:cameraactivity.resultlist){ log.d("tag", "onclick: eleman: " +st); } } }); builder.setnegativebutton(android.r.string.cancel, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }); alertdialog dialog = builder.create(); dialog.show(); } }
here xml files
fragment result list
<?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="match_parent" android:paddingleft="8dp" android:paddingright="8dp"> <listview android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="match_parent" android:drawselectorontop="false"/> <button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margintop="8dp" android:background="@drawable/cembutton" android:text="yükle" android:id="@+id/load" android:layout_alignright="@+id/results" android:focusable="false" android:focusableintouchmode="false" android:layout_alignparentbottom="true" android:textcolor="#ffffff" android:textstyle="bold"/> <textview android:id="@id/android:empty" android:layout_width="match_parent" android:layout_height="match_parent" android:text="no data"/> </relativelayout>
and fragment_rowlayout
<?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="match_parent" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_alignparenttop="true" > <textview android:id="@+id/mylisttext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="16dp" android:layout_margintop="16dp" android:textstyle="bold" android:textcolor="#3700ff" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawable="@drawable/cembutton" android:layout_alignparentright="true" android:text="Çıkart" android:layout_marginright="50dp"/> </relativelayout>
you should provide custom adapter listview
.
then, in getview()
method can find button id , set onclicklistener
it.
Comments
Post a Comment