I'm noob at Android Development. I would like to know if is it good praticse to use an hidden TextView as a identifier.
I frequently receive Json data, and I put the ID from the row inside a textview and I turn it invisible. I use this trick when I'm using a listview with clickable items.
Is it wrong to do that? Is there a better way to do the same thing?
Thanks.
To sum up the comments you've received:
I would like to know if is it good praticse to use an hidden TextView as a identifier.
No, it's not. Declaring view elements to be used in your program logic would violate the principles of separating view (xml) from your application logic (java). Also, as Luksprog pointed out;
It's not ok because you add one extra view (which costs in terms of performance) mostly for nothing.
Instead, use the Android framework callback method onListItemClick as suggested by Der Gol...lum:
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
//do something cleaver with the ID parameter
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With