public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radiobutton1:
if (checked)
// radio button 1 is selected.
break;
case R.id.radiobutton2:
if (checked)
// radio button 2 is selected.
break;
case R.id.radiobutton3:
if (checked)
// radio button 3 is selected.
break;
case R.id.radiobutton4:
if (checked)
// radio button 4 is selected.
break;
}
}
http://developer.android.com/guide/topics/ui/controls/radiobutton.
public View getView(final int arg0, View arg1, ViewGroup arg2) {
final ViewHolder vh;
vh= new ViewHolder();
if(arg1==null )
{
arg1=mInflater.inflate(R.layout.listviewsingleimg, arg2,false);
vh.iv1= (ImageView)arg1.findViewById(R.id.ivs);
vh.rb= (RadioButton) arg1.findViewById(R.id.radioButton1);
vh.tv= (TextView)arg1.findViewById(R.id.textView1);
}
else
{
arg1.setTag(vh);
}
vh.iv1.setImageResource(R.drawable.ic_launcher);
vh.tv.setText("hello");
vh.rb.setText("radioButton");
vh.rb.setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
if(arg0==1)
{
switch(v.getId()) {
case R.id.radioButton1:
if (vh.rb.isChecked())
// radio button 1 is selected.
Toast.makeText(c,"radiobutton 1 clicked",1000).show();
break;
}
}
}
});
return arg1;
}
static class ViewHolder
{
TextView tv;
RadioButton rb;
ImageView iv1;
}
The above displays toast when radiobutton in position 1 of listview is clicked.