android单击button后,获取某个控件的值,怎么获取?
展开全部
设置一个变量int whichEditText=0;在RadioGroup的监听事件中设置whichEditText的值
// RadioGroup的监听事件
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == rb_1.getId()) {
whichEditText= 1;
} else if (checkedId == rb_2.getId()) {
whichEditText= 2;
} else if (checkedId == rb_3.getId()) {
whichEditText = 3;
} else if (checkedId == rb_4.getId()) {
whichEditText= 4;
}else if (checkedId == rb_5.getId()) {
whichEditText= 5;
}
}
然后再在确认按钮的监听事件中,用switch语句根据whichEditText的值来选择获取哪个EditText的值
// RadioGroup的监听事件
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == rb_1.getId()) {
whichEditText= 1;
} else if (checkedId == rb_2.getId()) {
whichEditText= 2;
} else if (checkedId == rb_3.getId()) {
whichEditText = 3;
} else if (checkedId == rb_4.getId()) {
whichEditText= 4;
}else if (checkedId == rb_5.getId()) {
whichEditText= 5;
}
}
然后再在确认按钮的监听事件中,用switch语句根据whichEditText的值来选择获取哪个EditText的值
追问
那是一个listviewl来着
追答
那就把上面RadioGroup监听事件的部分改成
在listView的条目点击监听事件中实现:
先定义一个字符串变量data,再实现listView的条目点击事件
String data="";
@Override
public void onItemClick(AdapterView parent, View view, int position,
long id) {
// 找到item的控件
RadioButton rb = (RadioButton ) view
.findViewById(R.id.rb);
rb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
EditText et = (EditText ) view.findViewById(R.id.et);
data=et.getText().toString().trim();
}
});
}
最后在保存按钮的监听事件中用data就好了
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |