• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Problems with ListView getChild

Alfie0521

Lurker
Jan 25, 2011
2
0
I got the confusion while trying to simulate users to touch ListView as below:

ListView mList = (ListView)getActivity().findViewById(android.R.id.list);
Log.i("Music", "mList isFocused: " + mList.isFocused());
Log.i("Music", "getChildAt(-1): " + mList.getChildAt(-1));
Log.i("Music", "getChildAt(0): " + mList.getChildAt(0));
Log.i("Music", "getChildAt(1): " + mList.getChildAt(1));
Log.i("Music", "getChildAt(2): " + mList.getChildAt(2));
Log.i("Music", "mList_ChildCount: "+ mList.getChildCount() );
TouchUtils.clickView(this, mList.getChildAt(0));

Output:
mList isFocused: true
getChildAt(-1): null
getChildAt(0): android.widget.RelativeLayout@46bfe620
getChildAt(1): android.widget.RelativeLayout@46c01a08
getChildAt(2): null
mList_ChildCount: 2

and this is to click on the list of index 0 as expected.
What Im confused about is that it is to touch the view of index 0
although I change code to:
TouchUtils.clickView(this, mList.getChildAt(1)); WHY? :eek:

While declaring mList.getChildAt(), only index 0 is shown on hint for possible value. index 1 is gone?!!

Anyone has any idea :thinking:
Thanks a lot!
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones