I have an android application which uses listview.Each row consist of ImageView,a TextView and a CheckBox. I want to get selected items from this listview.I used
private void getSelectedItems() {
        List<String>list = new ArrayList<String>();
        try {
            SparseBooleanArray checkedItems = new SparseBooleanArray();
            checkedItems = listView.getCheckedItemPositions();
            if (checkedItems == null) {
                return;
            }
            final int checkedItemsCount = checkedItems.size();
            for (int i = 0; i < checkedItemsCount; ++i) {
                int position = checkedItems.keyAt(i);
                boolean bool = checkedItems.valueAt(position);
                if (bool) {
                   list.add(mainList.get(position));
                }
            }
        } catch (Exception e) {
        }
    }
But i want to set some items as checked with respect to a condition at start up.The checked item obtain only when if the user check/Uncheck an item.No checked item obtain even if the item is set as checked at the start up programmatically.What is the problem here?
Thanks in Advance