我陷入了需要获取选中的 Radiobutton 的 ID 的情况。我知道问题出在哪里,但我无法解决,所以请根据我的代码建议我。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
bean=arrayListCountry.get(position);
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
if(convertView==null)
{
convertView=inflater.inflate(R.layout.custom_layout_listview, null);
holder=new ViewHolder();
holder.textCountryName=(TextView)convertView.findViewById(R.id.textView1);
holder.radioCountry=(RadioButton)convertView.findViewById(R.id.radioButton1);
RelativeLayout relativeLayout=(RelativeLayout)convertView.findViewById(R.id.relativeCustomLayout);
relativeLayout.addView(convertView);
convertView.setTag(holder);
convertView.setTag(R.id.textView1,holder.textCountryName);
}
else
holder=(ViewHolder)convertView.getTag();
holder.radioCountry.setTag(position);
holder.textCountryName.setText(bean.getCountryName());
holder.radioCountry.setChecked(bean.getIsSelected());
holder.radioCountry.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
int pos=(Integer)buttonView.getTag();
Country_Bean country_Bean=arrayListCountry.get(pos);
coubean.setIsSelected(buttonView.isChecked());
//buttonView.setChecked(bean.getIsSelected());
Toast.makeText(context, "POs:"+pos+"\ncountry:"+bean.getCountryName()+"\ncountry_check:"+bean.getIsSelected()+"\nbuttonCheck:"+buttonView.isChecked(), Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
请告诉我如何获得特定的单选按钮。我也想知道为什么通常使用 getView 以及我们如何手动调用该方法。提前谢谢你。