[英]I have checkbox, imageview and textview in android, I want to check my checkbox when i click the associated textview
Here is my code. 这是我的代码。
if (view == null) {
view = lInflater.inflate(
R.layout.list_item_multiple_choice, null);
vHolderMultiple = new ViewHolder();
vHolderMultiple.tv = (TextView) view.findViewById(R.id.tvMultipleChoiceListItem);
vHolderMultiple.cb = (CheckBox) view.findViewById(R.id.cbMultipleListItem);
vHolderMultiple.iv = (ImageView) view.findViewById(R.id.ivMultiChoiceItem);
view.setTag(vHolderMultiple);
}
else {
vHolderMultiple = (ViewHolder) view.getTag();
}
vHolderMultiple.tv.setText(optionArray.get(position).getOptionText());
vHolderMultiple.cb.setChecked(lvAnswers.isItemChecked(position));
if (optionArrayCopy.get(position).getImageUrl() != null && optionArrayCopy.get(position).getImageUrl().length() > 0) {
final Bitmap bmp = loader.loadImageBitmap(optionArray.get(position).getImageUrl(), resDir);
vHolderMultiple.iv.setVisibility(VISIBLE);
if (bmp != null) {
vHolderMultiple.iv.setImageBitmap(bmp);
}
} else
vHolderMultiple.iv.setImageBitmap(null);
Same issue is occurred with checkbox with listview. 带有listview的复选框发生相同的问题。
Use CheckedTextView UI component 使用CheckedTextView UI组件
OR 要么
You need to code that manually. 您需要手动进行编码。 Add the setonclicklistner to Textview & pass the checkbox object to it.
将setonclicklistner添加到Textview并将复选框对象传递给它。 On net lots of code sample available.
大量的代码示例可用。
Simply add a OnClickListener to the TextView and check/uncheck the CheckBox inside it. 只需将OnClickListener添加到TextView并选中/取消选中其中的CheckBox。 Something like this:
像这样:
vHolderMultiple.tv.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(vHolderMultiple.cb.isChecked())
vHolderMultiple.cb.setChecked(false);
else
vHolderMultiple.cb.setChecked(true);
}
});
Note that you must declare cd as final in order to be able to change its state from an OnClick method. 请注意,必须将cd声明为final才能从OnClick方法更改其状态。
It seems like you are using ListView to show some texts with image and checkbox. 似乎您正在使用ListView来显示带有图像和复选框的某些文本。
It's better to use a CheckedTextView instead, which is a TextView combined with a CheckBox. 最好改用CheckedTextView,它是结合了CheckBox的TextView。 And use TextView.setCompoundDrawablesWithIntrinsicBounds() to replace the ImageView.
并使用TextView.setCompoundDrawablesWithIntrinsicBounds()替换ImageView。
Then you can enable multiple choice mode by ListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE). 然后,可以通过ListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE)启用多选模式。 And ListView will helps to manage the check state of each row.
ListView将有助于管理每一行的检查状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.