0

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);
}
JB.Dev
  • 25
  • 4
  • Please provide a minimum code snippet that shows what are you trying to do – Ionut J. Bejan Oct 19 '17 at 09:32
  • I added some code. It may show that I am doing something wrong. – JB.Dev Oct 19 '17 at 11:10
  • Invoking lvMain.invalidateViews () calls MainCursorAdapter.bindView (View view, Context context, Cursor cursor). When reconnecting data from Cursor to View re-connect events to the ListView? – JB.Dev Oct 19 '17 at 11:16
  • I found a solution to the problem. I guess I was wrong in defining the problem. I gave too little information, which turned out to be of great importance. The problem is the same as in the link below: https://stackoverflow.com/questions/9900913/onitemclicklistener-was-not-work-with-the-checkbox – JB.Dev Oct 20 '17 at 06:59

0 Answers0