Android - ListView - performItemClick

前端 未结 24 1284
清歌不尽
清歌不尽 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:46

    Using the code @sulal proposed, you may place it in onLoadFinished, if you use a LoaderManager. Eg something like

    @Override
    public void onLoadFinished(Loader loader, Cursor data) {
        //....
        // mSelectedId keeps the currently selected id
        // INVID is an invalid value
        if (mSelectedId == INVID) { // nothing selected
            // sulal's code
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    mList.performItemClick(
                            mList.getChildAt(mActivePosition),
                            mActivePosition,
                            mList.getAdapter().getItemId(mActivePosition));
                    mSelectedId = mList.getAdapter().getItemId(mActivePosition);
                }
            });            
        }
    

    mActivePosition may be 0 (ie position on the first item) or a position kept during eg onPause

提交回复
热议问题