I'm a beginner when it comes to Android. When I refresh the ListView using the invalidateViews () method, the events that are connected to ListView.setOnItemClickListener (event1), setOnItemLongClickListener (event2) stop working. ListView is connected to a CursorAdapter that provides data. In CursorAdapter.bindView, data is binded to views.
The whole code is pretty big. I will try to give in my opinion the most important pieces of code and add an explanation.
I add yet, if the connection events in the MainCursorAdapter.bindView (...) method are all working correctly.
Thank you for your help.
// 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);
}