我的列表视图有问题(2 个文本视图和 1 个单选按钮)。
问题:我的想法是用户单击列表视图中的项目,然后自动选中单选按钮。
我已经搜索了一段时间,但我无法让单选按钮工作。
我的 XML
<RadioButton
android:id="@+id/rdBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
我的适配器
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;
我试过
r.setChecked(true);
在我的活动类中,第一次单击有效,但第二次在列表视图中选择了不同的项目。
我希望你们中的一些人可以帮助我。谢谢