I have another list that shows a list of data from the database when I select any row to show this data Instead of data, instead of data, I want the primary key ID of that data. The list view should be shown on the list BT onclicks, the primary key ID of that data should be received
public zero onClick (See v) {cursor c = db raw ("select" * from the dal C ", null); Value = new arreelist & lt; String & gt; (); While (c.moveToNext ()) {string uname = c.getString (c.getColumnIndex ("delta")); If (uname! = "") Values.add (uname); Println ("data" + uname); } // All data is an ArrayAdapter & lt; String & gt; Adapters = new arreptopter & lt; String & gt; (This, Android R Outout. Simple_l_Link_active, value); ListView.setAdapter (adapter); }
In this way, I create listview how to tag the primary key ID for the row in listview
You will need to create a custom adapter, give it a try:
public class CustomAdapter BaseAdapter {Private reference mContext; Private listing & lt; Pair & lt; Integer, string & gt; & Gt; MData; Public CustomAdapter (reference reference, list & lt; add & lt; integer, string & gt; & gt; data) {this.mContext = context; This.mData = Data; } @ Override Public In Receipt () {return mData.size (); } @ Override Public Couple & lt; Integer, string & gt; GetItem (int position) {return mData.get (status); } @ Override public long ITMID (status of int) {return status; } @ Override Public View getView (int position, seeviewview, ViewGroup parents) {View view = convertView; See (see == faucet) = Layout Inflator. From (MCTXT). Inflat (Android.r.lt. simple_list_item_activated_1, guardian, incorrect); String text = ditim (position). Seconds; (See TextView) .set text (text); Return view; }}
Instead of your activity:
list & lt; Pair & lt; Integer, string & gt; & Gt; Values; Click Public Zero (see V) {cursor C = db.rawQuery ("select * Deltaas", blank); Value = new Arrivate & lieutenant; Pair & lt; Integer, string & gt; (); While (c.moveToNext ()) {string uname = c.getString (c.getColumnIndex ("delta")); Int id = c.getInt (c.getColumnIndex ("id")); If (uname! = "") Pair & lt; Integer, string & gt; Couple = new couple & lt; Integer, string & gt; (Id, uname); Values.add (pair); Println ("data" + uname); } C. Close (); // Get the same data via a custom adapter adapter = new custom aadapter (main activity. ListView.setAdapter (adapter); }
Then get your stuff:
listView.setOnItemClickListener (new adapter view. OniteClicklist) {@Override & Lt ;? & gt; parent, view view, integer position, long id) {custom adapter adapter = (custom adapter) parent.getAdapter (); jouher & lt; integer, string & gt; pair = adapter.getitim ( Status); log.e ("you need the information", "id:" pair.first + "name:" + pair.second);}}}});
No comments:
Post a Comment