Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good pratice to use an hidden TextView as a identifier? [closed]

Tags:

android

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.

like image 656
Tony Avatar asked Nov 25 '25 17:11

Tony


1 Answers

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
}
like image 95
Marcus Avatar answered Nov 28 '25 06:11

Marcus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!