android - ListView 和 ArrayAdapter 与 simple_list_item_multiple_choice
以下代码创建一个 ArrayAdapter,并在 onResume() 中使用 ListView.setItemChecked() 更改每个 CheckedTextView
的状态代码>.
这一切都很好。
有没有办法可以禁用(灰显)一些 CheckedTextViews
?
我尝试使用 adapter.getView(position, null, listView)
,虽然这会返回 CheckedTextView
对象,但将其设置为 setclickable(false)
代码> 不执行任何操作。我尝试过更改其文本并更改状态,但它也没有执行任何操作。
我怎样才能实现这个目标?
下面是运行良好的代码:
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
getResources().getStringArray(R.array.mode_declarations_array));
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
String learningSettings = settings.getString(Constants.LEARNING_SETTINGS, null);
int count = adapter.getCount();
if (learningSettings != null ) {
String[] values = learningSettings.split(",");
for (int i = 0; i< values.length; i++) {
boolean val = Boolean.parseBoolean(values[i]);
listView.setItemChecked(i, val);
}
}else {
for (int i = 0; i<count; ++i) {
listView.setItemChecked(i, true);
}
}
The following code creates an ArrayAdapter
and I change the state of each CheckedTextView
using ListView.setItemChecked()
in onResume()
.
This is all fine.
Is there a way I can disable (grey out) some of the CheckedTextViews
?
I've tried using adapter.getView(position, null, listView)
, and while this returns a CheckedTextView
object, setting it to setclickable(false)
doesn't do anything. I've tried changing its text and changing the state but it doesn't do anything either.
How can I achieve this?
Below is the code that works fine:
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
getResources().getStringArray(R.array.mode_declarations_array));
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
String learningSettings = settings.getString(Constants.LEARNING_SETTINGS, null);
int count = adapter.getCount();
if (learningSettings != null ) {
String[] values = learningSettings.split(",");
for (int i = 0; i< values.length; i++) {
boolean val = Boolean.parseBoolean(values[i]);
listView.setItemChecked(i, val);
}
}else {
for (int i = 0; i<count; ++i) {
listView.setItemChecked(i, true);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建您的自定义适配器并覆盖
isEnabled
函数。Create a custom adapter of yours and override the
isEnabled
function.