1. Download our Official Android App: Forums for Android!

Problems with ListView getChild

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

  1. Alfie0521

    Alfie0521 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jan 25, 2011

    Jan 25, 2011
    2
    0
    5
    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!
     

    Advertisement

Share This Page

Loading...