0

Is it possible to have attributes on listviews something like:-

<string-array name="arr_sats">
<item id="0101">Sat 1</item>
<item id="0201">Sat 2</item>
</string-array>

Then on the click event get the value of 'id'?

Martin
  • 240
  • 4
  • 13

2 Answers2

0

onClick gives you a position. With that position, you can fetch the Item and thus have the id.

Fildor
  • 14,510
  • 4
  • 35
  • 67
  • Yeah I can get the position, but how do I actually get the id, which is something that I will enter manually when I create the list? – Martin Dec 12 '11 at 15:07
  • What kind of adapter are you using? http://developer.android.com/reference/android/widget/ArrayAdapter.html Using this one, there's "getItem(int position)" where you'll get a ListItem Object. From that object (in which you store your data) you can get your id. Perhaps you can give us some mor code of yours? Then we can say more, I'm pretty sure. – Fildor Dec 13 '11 at 08:37
0

onItemClick will give you position, then you have to parse xml and get the attribute of that position. See the following URL how to get 'name' attribute of item of string-array

Community
  • 1
  • 1
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • Struggling a little here, very new to android, any chance you have a clearer example (just me being thick). I would have thought something like this would have been much simpler – Martin Dec 12 '11 at 16:08