android listview每个item里面有个radiobutton,如何弄radibutton的单选事件
android listview每个item里面有个radiobutton,怎么弄radibutton的单选事件
如题 android listview每个item里面有个radiobutton,怎么弄radibutton的单选事件,点击某个radio的时候它选中,其他的取消, 牛人们,,,请给出具体的代码
在网上找的 都没有效果,要么就是只能点击一个不能换成其他的了,要么就是都选上了。。。
final RadioButton mRadioButton = (RadioButton) view
.findViewById(R.id.report_item_check);
mRadioButton.setChecked(false);//先把所有的设置为false
if(mRadioButton.getId()<=position){
mRadioButton.setId(position);
}
mRadioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//在这儿实现整个listView item 中的radioButton的单选
if(isChecked)
{
if(temp!=-1)
{
RadioButton tempRadio =(RadioButton)view.findViewById(temp);
if(tempRadio !=null)
{
tempRadio.setChecked(false);
}
}
temp = buttonView.getId();
}
}
});
if (position == mRadioButton.getId()) {
mRadioButton.setChecked(true);
} else {
mRadioButton.setChecked(false);
}
// radioButton.setId(position);
// radioButton.setChecked(false);
// radioButton
// .setOnCheckedChangeListener(new OnCheckedChangeListener() {
//
// public void onCheckedChanged(
// CompoundButton buttonView, boolean isChecked) {
// if (radioButton.isChecked()==true) {
// temp=btn_id;
// btn_id = radioButton.getId();
// if (temp != -1 && temp != btn_id) {
// RadioButton tempButton = (RadioButton) view
// .findViewById(temp);
// if (tempButton != null) {
// tempButton.setChecked(false);
// }
// }
// }
//
// }
// });
// if (btn_id == position) {
// radioButton.setChecked(true);
// checked_map=map;
// } else {
// radioButton.setChecked(false);
// }
//
如题 android listview每个item里面有个radiobutton,怎么弄radibutton的单选事件,点击某个radio的时候它选中,其他的取消, 牛人们,,,请给出具体的代码
在网上找的 都没有效果,要么就是只能点击一个不能换成其他的了,要么就是都选上了。。。
final RadioButton mRadioButton = (RadioButton) view
.findViewById(R.id.report_item_check);
mRadioButton.setChecked(false);//先把所有的设置为false
if(mRadioButton.getId()<=position){
mRadioButton.setId(position);
}
mRadioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//在这儿实现整个listView item 中的radioButton的单选
if(isChecked)
{
if(temp!=-1)
{
RadioButton tempRadio =(RadioButton)view.findViewById(temp);
if(tempRadio !=null)
{
tempRadio.setChecked(false);
}
}
temp = buttonView.getId();
}
}
});
if (position == mRadioButton.getId()) {
mRadioButton.setChecked(true);
} else {
mRadioButton.setChecked(false);
}
// radioButton.setId(position);
// radioButton.setChecked(false);
// radioButton
// .setOnCheckedChangeListener(new OnCheckedChangeListener() {
//
// public void onCheckedChanged(
// CompoundButton buttonView, boolean isChecked) {
// if (radioButton.isChecked()==true) {
// temp=btn_id;
// btn_id = radioButton.getId();
// if (temp != -1 && temp != btn_id) {
// RadioButton tempButton = (RadioButton) view
// .findViewById(temp);
// if (tempButton != null) {
// tempButton.setChecked(false);
// }
// }
// }
//
// }
// });
// if (btn_id == position) {
// radioButton.setChecked(true);
// checked_map=map;
// } else {
// radioButton.setChecked(false);
// }
//
- 1Android快速开发必不可少的11个工具类
- 2android 语言定做
- 3Android带明白按钮的EditText
- 4listview 动态添加,该如何解决
- 5eclipse中怎么修改项目名称 具体操作
- 6Android学习笔记19:含有通知栏的进度条的Android下载文件
- 7android GPS 获取定位坐标信息解决方法
- 8FBReaderJ学习笔记(3):Footer底部状态栏更改
- 9(原)Android理论梳理-No1异步处理之Handler相干机制
- 10ScrollView里嵌套ListView,怎么禁用ListView的滚动事件,或者触发ListView滚动时调用父元素ScrollView的滚动事件
文章评论
相关解决方案
- 1android listview(每个item包孕图片及文字)
- 2Listview每个item中包含fragment,适配器如何写
- 3android-listview 兑现radiobutton 单选
- 4设立ListView每个item点击背景图片设置
- 5怎么动态修改ListVIew中每个Item的值
- 6ListView的每个item中左右滑动的时候, 怎么不让item有选中的效果
- 7QT中继承QListView自定义类如何重构里面的对每个Item的绘图
- 8如何在XlistView每个Item中间在加别的内容 里面有效果图,求大神解答!在弄不出要被炒了
- 9ListBox有多个相同内容时如何返回每个item的index
- 10ListView里的每个item有两个textView跟一个checkBox