开发者

android.R.layout.simple_list_item_checked not toggling in ListView

开发者 https://www.devze.com 2023-02-01 09:21 出处:网络
Here is my custom adapter: ... @Override public View newView(Context context, Cursor cursor, ViewGroup parent) {

Here is my custom adapter:

...
@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;
}
...

Now this visually appears to be exactly what I needed. The 开发者_开发问答problem is that I can't get toggle the checked state when I click on the listview item. Any solutions?


I quickly found a sloppy way of doing this:

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


Mohit, Why don't you try this:

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) {
    CheckedTextView textview = (CheckedTextView)v;    
    textview.toggle();
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号