My app's UI has a ListView to show the timeline of tweets and setup an OnItemLongClickListener
to show another view with several buttons ("Reply", "Retweet", "Favorite", etc.). inside my Adapter's getView()
method.
What I want: In my test project, I want to test this feature by performing a long click on the first item in the timeline and then performing a click on one of the buttons.
The part of code looks like below:
timelineList.getChildAt(0).performLongClick();
favoriteBtn = (ToggleButton)timelineList.getAdapter().getView(0, null, timelineList).findViewById(cse.ust.twittermap.R.id.favorite);
favoriteBtn.performClick();
favoriteBtn.performClick();
timelineList.getChildAt(0).performLongClick();
This works but when I try to change the second line into:
timelineList.getChildAt(0).findViewById(cse.ust.twittermap.R.id.favorite);
The test project throws a NullPointer exception, because findViewById()
return null.
My Question: What is the difference between ListAdapter#getView()
and ListView#getChildAt()
?
It seems both of them can return a reference to an item view in the list, but clearly there should be some differences between them. I also want to figure out why the getChildAt()
method in the second line fails in finding views by Ids.