android.R.layout.simple_list_item_checked未在ListView中切换

Moh*_*nde 1 java android listview checkedtextview

这是我的自定义适配器:

...
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(android.R.layout.simple_list_item_checked, parent, false);
    return v;
}
...
Run Code Online (Sandbox Code Playgroud)

现在这看起来正是我所需要的.问题是当我点击listview项目时,我无法切换检查状态.有解决方案吗

Moh*_*nde 6

我很快发现了一种草率的方式:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    CheckedTextView textview = (CheckedTextView)v;
    textview.setChecked(!textview.isChecked());
}
Run Code Online (Sandbox Code Playgroud)