刷新列表视图后的事件问题

时间:2017-10-19 09:30:27

标签: android listview events android-cursoradapter

对于Android,我是初学者。当我使用invalidateViews()方法刷新ListView时,连接到ListView.setOnItemClickListener(event1),setOnItemLongClickListener(event2)的事件将停止工作。 ListView连接到提供数据的CursorAdapter。在CursorAdapter.bindView中,数据绑定到视图。

整个代码非常大。我将尝试在我看来提供最重要的代码片段并添加解释。

我添加了,如果MainCursorAdapter.bindView(...)方法中的连接事件都正常工作。

感谢您的帮助。

// Data binding to ListView
protected void bindDataWithList()
{
    if (checkCommunicatorWithActivity())
    {
        this.mainCursorAdapter = (MainCursorAdapter) this.communicatorWithActivity.getMainDataList();
        this.mainCursorAdapter.setListView(lvMain);
        lvMain.setAdapter(this.mainCursorAdapter);
    }
}

// Create event methods
protected void createEventsListener()
{
    this.lvOnItemClickListener = new AdapterView.OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
            Toast.makeText(getActivity(), "ItemClick(ListView)", Toast.LENGTH_SHORT).show();
            //ListFragment.this.communicatorWithActivity.showDetailListItem(position);
        }
    };

    this.lvOnItemLongClickListener = new AdapterView.OnItemLongClickListener()
    {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id)
        {
            Toast.makeText(getActivity(), "ItemLongClick(ListView)", Toast.LENGTH_SHORT).show();
            if (checkMainCursorAdapter())
            {
                ListFragment.this.mainCursorAdapter.setShowSelected(! ListFragment.this.mainCursorAdapter.getShowSelected());
                lvMain.invalidateViews();
                // after this method events not works !!! 
            }
            return true;
        }
    };
}

// Linking event methods

protected void bindEventsListener()
{
    lvMain.setOnItemClickListener(this.lvOnItemClickListener);
    lvMain.setOnItemLongClickListener(this.lvOnItemLongClickListener);
}

0 个答案:

没有答案