Question

I have Activity with ListView and buttons - "clear all" and "OK". On button "clear all" I clear checked state of items - it works fine.

m_list.setItemChecked(pos, false); 

On onItemClick I'm trying to change state of items/checked <-> unchecked/ depending on complicated business logic. Bussines layer decides checked or not for more than one item. I'm trying same code:

m_list.setItemChecked(position, bCheck); 

It is not working. Data behind is changed only view not.

"Clear all" code:

@Override
public void onClick(View v)
{
    if (v == m_map)
        GoToMap();
    else if (v == m_clear)
    {
        for (int i=0; i < m_poiCategories.size();i++)
        m_list.setItemChecked(pos, false);
    }
}

This code not working:

m_list.setOnItemClickListener(new OnItemClickListener()
    {
    @Override
    public void onItemClick(AdapterView<?> listView, View selectedItem, int position, long itemId)
    {
        boolean b = true;
        ....
        m_list.setItemChecked(position, b);
    }
});
Was it helpful?

Solution

If you are working with ListViews than it is required that notifyDataSetChanged() to be called from the UI thread when any data is changed. This will update the UI by calling getView() several times, depending how many items are displayed.

Make sure your getView() is properly implemented.

For reference I highly recommend to view and understand: http://www.youtube.com/watch?v=wDBM6wVEO70

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top