2

I have the following setup:

Activity:

public class UploadActivity extends AbstractListActivity {

    protected PackageAdapter mAdapter = new PackageAdapter();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        setListAdapter(mAdapter);
    }
}

Adapter:

public class PackageAdapter extends ArrayAdapter<PointPackage> {

    ...

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        TextView view;
        if (convertView == null) {
            view = (TextView) mInflater.inflate(R.layout.list_item_package, parent, false);
        } else {
            view = (TextView) convertView;
        }

        bind(getItem(position), view);

        return view;
    }

    private void bind(PointPackage item, TextView view) {
        view.setText(item.getName());
    }
}

activity_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

list_item_package.xml:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:drawableLeft="@drawable/collection"
    android:drawablePadding="@dimen/compactPadding"
    android:gravity="center_vertical"
    android:textAppearance="?android:attr/textAppearanceListItem" />

My problem is that the list items are not getting selected when clicked... The row is seems to be clickable, it highlights when clicked, but the checkmark does not appears. What am i doing wrong?

EDIT: This code is just fine. The problem was elsewhere.

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
  • Look at http://theopentutorials.com/tutorials/android/listview/android-multiple-selection-listview/ tutorial. Maybe you should try android.R.layout.simple_list_item_multiple_choice layout. – sianis Feb 21 '14 at 12:55
  • Thanks for your answer! It was not the problem. Actually [that layout](https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_list_item_multiple_choice.xml) also consists of one `CheckedTextView`, with different height, text size and padding. – WonderCsabo Feb 21 '14 at 19:25

1 Answers1

1

You need to implement the onItemClick Listener and in there you can get the view/item which was clicked. From that view get the CheckedTextView and mark it is as checked.

Mobility
  • 263
  • 2
  • 5