Android how to get "name" from clicked item -
i need item name listview clicked item.
the list populated items.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="menu_dx_items"> <item name="0">a</item> <item name="7">b</item> <item name="2">c</item> </string-array> </resources> i succesfully got strings ("a","b" or "c") clicking items in way:
final listview menudx = (listview) findviewbyid(r.id.menu_dx); menudx.setonitemclicklistener(new adapterview.onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, final int pos,long id){ string item_text = (string) parent.getitematposition(pos); toast.maketext(getapplicationcontext(), item_text , toast.length_short).show(); } }); now i'm trying "name" parameter of clicked item, suggestions?
it not possible, name resource id can used reference object. (seen here: http://developer.android.com/guide/topics/resources/string-resource.html#stringarray)
one workaround may have separate string array "maps" array, when know index click (say "a" clicked), can check "map" array value should associated a.
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="menu_dx_items"> <item>a</item> <item>b</item> <item>c</item> </string-array> </resources> <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="menu_dx_item_map"> <item>0</item> <item>7</item> <item>2</item> </string-array> </resources> and
final listview menudx = (listview) findviewbyid(r.id.menu_dx); menudx.setonitemclicklistener(new adapterview.onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, final int pos,long id){ string item_text = (string) parent.getitematposition(pos); // now, value map array string item_val = getresources().getstringarray(r.array.menu_dx_item_map)[pos]; toast.maketext(getapplicationcontext(), item_text + " = " + item_val, toast.length_short).show(); } }); android
No comments:
Post a Comment