Android - ListView - performItemClick

前端 未结 24 1164
清歌不尽
清歌不尽 2020-11-29 03:10

I\'m facing some difficults when I try to use the performItemClick funcion of the ListView.

All I want to do is to perform a click programatically i

相关标签:
24条回答
  • 2020-11-29 03:48
    mList.performItemClick(
        mList.getChildAt(mActivePosition),
        mActivePosition,
        mList.getAdapter().getItemId(mActivePosition));
    

    where mActivePosition is the position of the child view in List View.

    0 讨论(0)
  • 2020-11-29 03:50

    getListView().performItemClick(null, 0, 0) did the trick for me (for position 0).

    0 讨论(0)
  • 2020-11-29 03:51
    mList.performItemClick(
            mList.getAdapter().getView(mActivePosition, null, null),
            mActivePosition,
            mList.getAdapter().getItemId(mActivePosition));
    

    Where mActivePosition is your click position! All the best! :)

    0 讨论(0)
  • 2020-11-29 03:51

    The performClick is probably called before listview was filled, put breakpoint in getView and on performItemClick and check wich is called first

    0 讨论(0)
  • 2020-11-29 03:54

    If you are working on a unit test case. Try to use getInstrumentation().waitForIdleSync(), to wait the list be loaded, and extend the ActivityInstrumentationTestCase2 See this answer.

    0 讨论(0)
  • 2020-11-29 03:55

    In my case, none of the options solved my problem, so I made an adaptation in my CursorAdapter class. I defined a global variable in the scope, so I just call the class changing this value and check the cursor position by passing the position value

     mProductsAdapter.currentPosition = requiredPosition
    

    in my ProductsAdapter builder

      var currentPosition = 0
    

    in bindView I do the check

     if (cursor.position == currentPosition) {
    // perform action
    }
    
    0 讨论(0)
提交回复
热议问题