Textview和Checkbox在Recyclerview中。最初选中所有复选框。我想阻止用户更改Checkboxes状态,但我不想阻止Recyclerview滚动。我想在我的片段类中而不是在适配器类中这样做。
如何阻止用户更改Checkboxes状态?
以下是适配器类中onBindViewHolder编写的示例代码。
holder.cbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//set your object's last status
tblFilm.setSelected(isChecked);
}
});
以上代码用于第一种模式,允许用户点击 复选框。
之后我有第二种模式,我不想被点击 复选框。
我已经完成了以下工作。
optionsoff(recyclerView);
private static void optionsOff(ViewGroup layout) {
layout.setEnabled(false);
layout.setClickable(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
optionsOff((ViewGroup) child);
} else {
child.setEnabled(false);
child.setClickable(false);
}
}
我猜这optionsoff()
无效。因为它没有禁用复选框。我仍然可以点击复选框。我需要有关第二种方法的帮助,该方法禁用了Recyclerview项目。
答案 0 :(得分:4)
答案 1 :(得分:1)
Mayby尝试这样的事情?
<CheckBox
android:id="@+id/server_is_online"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:clickable="false"
android:text="@string/server_is_online"
android:textSize="23sp" />
以编程方式在您的适配器(扩展BaseAdapter)中添加
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowbuttonlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.checkbox.setChecked(true);
holder.checkbox.setEnabled(false);
}
类的好例子扩展了BaseAdapter here。