How to get information from a customized ListView in Android -
i have listview have customized display information gathered sqlite database. each item represented using cardview widget containing textviews. have set listview property in .xml file to:
android:choicemode="singlechoice"
allowing user make selection list.
when user clicks floating action button, want able take information displayed in 1 of textviews of cardview selected in listview.
i have looked @ other questions on topic , suggest using onclick method, not understand how work because not want retrieve information when user makes selection list. rather, want information when have selected floating action button.
here part of activity code:
public class setvieweractivity extends appcompatactivity { private static final string tag = "setvieweractivity"; private boolean fabstate; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // set contents of activity setcontentview(r.layout.activity_set_viewer); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); // set action main floating action button floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fabstate = false; fab.setonclicklistener(new view.onclicklistener() { // set info , edit in new activity @override public void onclick(view view) { editselectedset(view); } }); // set list view , populate custom set info database sqlitedatabase db = new memcardsqlitehelper(this).getreadabledatabase(); cursor cursor = db.rawquery(memcarddbcontract.sets.select_all_sets, null); listview lvsets = (listview) findviewbyid(r.id.listviewsets); setviewadapter adapter = new setviewadapter(this, cursor); lvsets.setadapter(adapter); } private void editselectedset(view view) { // how find set information here ?? // start activity selected set information editing intent intent = new intent(this, createnewset.class); intent.putextra(mainactivity.create_set_num, selectedset); startactivity(intent); } }
and here xml each listview item:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp"> <android.support.v7.widget.cardview android:layout_width="wrap_content" android:layout_height="match_parent" app:cardcornerradius="4dp" app:cardelevation="2dp" app:contentpadding="2dp"> <android.support.constraint.constraintlayout android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:id="@+id/textviewname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="8dp" android:layout_marginright="8dp" android:layout_margintop="8dp" android:layout_weight="1" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" /> <textview android:id="@+id/textviewamount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="8dp" android:layout_marginright="8dp" android:layout_margintop="8dp" android:layout_weight="1" app:layout_constrainthorizontal_bias="0.0" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_tobottomof="@+id/textviewname" /> <textview android:id="@+id/textviewcolour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="8dp" android:layout_marginright="8dp" android:layout_margintop="10dp" android:layout_weight="1" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainthorizontal_bias="0.0" app:layout_constrainttop_tobottomof="@+id/textviewamount" /> <textview android:id="@+id/textviewsetid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> </android.support.constraint.constraintlayout> </android.support.v7.widget.cardview> </linearlayout>
you can assign onclick on each item , when item selected (clicked) can save data field member. read data ever want.
Comments
Post a Comment