Cam*_*amo 2 android listview android-radiobutton
我的列表视图(2 个文本视图和 1 个单选按钮)有问题。
问题:我的想法是用户单击列表视图中的项目,单选按钮会自动选中。
我已经搜索了一段时间,但无法让单选按钮工作。
我的 XML
<RadioButton
android:id="@+id/rdBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
Run Code Online (Sandbox Code Playgroud)
我的适配器
r = (RadioButton) convertView.findViewById(R.id.rdBtn);
r.setChecked(selectedPosition == position);
r.setTag(position);
r.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//r.setChecked(true);
Toast.makeText(context, InformationActivity.result,
Toast.LENGTH_SHORT).show();
selectedPosition = (Integer) view.getTag();
notifyDataSetInvalidated();
}
});
return convertView;
Run Code Online (Sandbox Code Playgroud)
我试过
r.setChecked(true);
Run Code Online (Sandbox Code Playgroud)
在我的活动类中,第一次单击有效,但第二次单击在列表视图上选择了不同的项目。
我希望你们中的一些人可以帮助我。谢谢
我在这里找到了解决方案: How to check box on click an image?
searchList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {
LinearLayout item_view = (LinearLayout) view;
final RadioButton itemcheck = (RadioButton) item_view
.findViewById(R.id.rdBtn);
if (itemcheck.isChecked()) {
itemcheck.setChecked(true);
} else {
itemcheck.setChecked(false);
}
itemcheck.setChecked(true);
<RadioButton
android:id="@+id/rdBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9202 次 |
| 最近记录: |