Android的ListView控件:: setItemChecked不起作用 [英] Android ListView::setItemChecked doesn't work

查看:459
本文介绍了Android的ListView控件:: setItemChecked不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图表明简单的检查清单,我需要检查一些项目。

I tried to show simple checked list and I need some items to be checked.

下面是我的code

ArrayAdapter<任务> taskAdapter =新的ArrayAdapter<任务>(这一点,android.R.layout.simple_list_item_checked,tasksList);         。this.getListView()setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);         this.getListView()setItemChecked(2,真)。         setListAdapter(taskAdapter);

ArrayAdapter<Task> taskAdapter = new ArrayAdapter<Task>(this, android.R.layout.simple_list_item_checked, tasksList); this.getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); this.getListView().setItemChecked(2, true); setListAdapter(taskAdapter);

<ListView
   android:id="@android:id/list"
   android:layout_width="match_parent"
   android:layout_height="wrap_content">

和它仍然无法正常工作。 可检查的接口的实现并没有帮助。

And still it doesn't work. Implementation of Checkable interface didn't help.

这是什么的ListView的把戏?

What's the trick of this ListView?

推荐答案

您需要设置的选项为可检查的前设置的适配器。

You need to set the adapter before setting the item as checkable.

ArrayAdapter<Task> taskAdapter = new ArrayAdapter<Task>(this, android.R.layout.simple_list_item_checked, tasksList);
setListAdapter(taskAdapter);        
this.getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 
this.getListView().setItemChecked(2, true); 

适配器包含存储在列表视图中的数据,以便第2项不会在ListView存在,直到将适配器设置

The adapter contains the data stored in the listview so Item 2 does not exist in the listview until the adapter is set.

这篇关于Android的ListView控件:: setItemChecked不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆