Android listview multiple choice -


How to obtain selected multichoice list view data I have a list view with multiple choices and I selected listview in string array I want to store the item. Can someone direct me how I store the selected list of list observation in string array?

  SparseBooleanArray selected items = lv.getCheckedItemPositions (); Int id1 = lv.getCheckedItemPosition (); Toast. Make Text (getApplicationContext (), "" + id1, Toast. LNNGHIHORT) Show (); For (; I & lt; i = 0 int lv_arr.length; i ++). {If (selectedItems.get (i)) {String [] GetString = (string) lv.getAdapter () GetItem (selectedItems.keyAt (i)); Println ("+" + GetString); }}    

Hey, I've used the string to save all checked items from the list Used. See the code below:

  Import android.app.activity; Importroid.os.Bundle; Import android.util.log; Import android.util.SparseBooleanArray; Import android.view.View; Import android.widget.AdapterView; Import android.widget.AdapterView.OnItemClickListener; Import android.widget.ArrayAdapter; Import android.widget.ListView; Public class increases visibility activity {Private ListView lView; Private String lv_items [] = { "Android", "iPhone", "BlackBerry", "AndroidPeople", "J2ME", "List View", "ArrayAdapter", "ListItem", "our", "Britain", " India" }; Private string my_sel_items; @ Override Public Wide On Crate (Bundle Avalanche) {Super; Nectar; SetContentView (R.layout.main); My_sel_items = new string (); LView = (ListView) findViewById (R.id.ListView01); LView.setAdapter (new ArrayEdapter & lt; string & gt; (this, Android R. out. Simple_list_item_multiple_choice, lv_items)); LView.setChoiceMode (ListView.CHOICE_MODE_MULTIPLE); LViewksetOnItemClickListener (New OnItemClickListener () {public void onItemClick (AdapterView arg0, see ARG1, ARG2 integer, long arg3) {// List = new ArrayList (); my_sel_items = new String ( "selected items"); SparseBooleanArray a = for lView.getCheckedItemPositions (); (int i = 0; i & LT; lv_items.length; i ++) {if (a.valueAt (i)) {/ * Long val = lView.getAdapter () getItemId (a .keyAt (.i)); Log.v ("MyData", "index =" + val.toString () + "item value =" + lView.getAdapter (). GetItem (i)); list.add (lView .getAdapter () .getItemId ((a.keyAt (i)))), * / my_sel_items = my_sel_items + "," + (string) lView.getAdapter () GetItem (i) ;.}} Log.v ( "values ", My_sel_items);}}); }}    

Comments