1. Are you ready for the Galaxy S20? Here is everything we know so far!

Problems with ListView getChild

Discussion in 'Android Apps & Games' started by Alfie0521, Feb 16, 2011.

  1. Alfie0521

    Alfie0521 Lurker
    Thread Starter

    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));

    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!

    1. Download the Forums for Android™ app!



Share This Page