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< va开发者_开发百科lues.length; i++) {
boolean val = Boolean.parseBoolean(values[i]);
listView.setItemChecked(i, val);
}
}else {
for (int i = 0; i<count; ++i) {
listView.setItemChecked(i, true);
}
}
Create a custom adapter of yours and override the isEnabled
function.
class MyAdapter extends ArrayAdapter<String> {
public boolean areAllItemsEnabled() {
return false;
}
public boolean isEnabled(int position) {
// return false if position == position you want to disable
}
}
精彩评论