Is it correct to use a hidden TextView as an identifier?
I'm a nob in Android Development. I would like to know if it is correct to use a hidden TextView as an id.
I get Json data often and I put the ID from the string inside the text view and I make it invisible. I use this trick when I use a listview with clickable items.
Is it wrong to do this? Is there a better way to do the same?
Thank.
source to share
To summarize the comments you received:
I would like to know if it is correct to use a hidden TextView as an id.
No no. Declaring view elements to be used in your programming logic will violate the principles of splitting the view (xml) from your application logic (java). Also, as Luxprog pointed out;
This is not ok because you add one extra view (which is worth it in terms of performance) for basically nothing.
Instead, use the Android platform 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
}
source to share