0

I have a ListView that contain several TextViews. Once a TextView is pressed I get the onClick called with the view. What is the best practice to get the other text views on that row? IDs of the text views are similar along the rows so I need to keep on the context of the given view. I would guess I need to get the Parent of the given view and then grab the rest of the text views from it.

Thanks.

Simon
  • 509
  • 7
  • 25
  • Please post some relevant code. Are you using a ListActivity with onListItemClick, a regular Activity with a ListView and onItemClick or something different? – Sam Apr 30 '12 at 15:28

1 Answers1

0

Yeah, you would need to get the parent of the current textview, then get all the children contained within that parent.

Depending on what you need to do with the textviews you could either call FindViewById on the parent view to get each TextView by ID. Or you can iterate through the children as suggested in this question/answer: Android - get children inside a View?

I know people mention that calling FindViewByID is a taxing process, so consider storing the references to the textview's in some sort of object so you can quickly get the references to the other textview's within the row without having to look them up all the time.

ViewHolder's work pretty well, as they store the references to the textview's within an object (which you only need to fill once during creation) but it requires setting up your own customized adapter.

Community
  • 1
  • 1
Gophermofur
  • 2,101
  • 1
  • 14
  • 14
  • Can you please elaborate on how I use FindViewById and do it with the context of the parent view? I am asking since the same IDs exist for each row. – Simon Apr 30 '12 at 15:35