I am developing an application.I have a button to add some users when I click a button it displays a list of radio buttons which are nothing but users(contacts) where I can select multiple users my problem is that I can select any user a select but i cannot deselect the user which is already selected I have used
buttonView.setEnabled(false);
this statement but I am unable to deselect can any help me.
I have used arrayadapter to display in list view. this is the following code
Main class
public class Contactselectuser extends Activity {
Contactadapter contactadapteruser;
private ArrayList<String> listexample;
Button conform;
private ListView list;
ImageButton close;
boolean check;
RadioButton rb;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.selectrepresentative);
conform = (Button) findViewById(R.id.Confirm);
list = (ListView) findViewById(R.id.selectrecipientslist);
listexample=new ArrayList<String>();
getlist();
close=(ImageButton)findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
contactadapteruser = new Contactadapter(Contactselectuser.this,
R.layout.selectrepresentative, listexample);
list.setAdapter(contactadapteruser);
private void getlist() {
// TODO Auto-generated method stub
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (D)");
listexample.add("Rep. Name (D)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (D)");
listexample.add("Rep. Name (R)");
listexample.add("Rep. Name (D)");
listexample.add("Rep. Name (R)");
}
}
Adapter class New adapter class
public class Contactadapter extends ArrayAdapter<String> {
private Context context;
boolean value;
ListView list;
private ArrayList<String> listexample;
public Contactadapter(Context con, int layout, ArrayList<String> listexample) {
super(con, com.arivoli.amev.R.layout.selectrepresentative, listexample);
this.context = con;
this.listexample = listexample;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.selectradio, parent, false);
RadioButton rb=(RadioButton) rowView.findViewById(R.id.radioButton1);
rb.setText(listexample.get(position));
value = rb.isChecked();
//Toast.makeText(context, "status"+value, 5000).show();
rb.setTag(value);
rb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RadioButton radio=(RadioButton)v;
if(radio.isChecked()){
radio.getTag();
value = radio.isChecked();
radio.setChecked(value);
value=false;
}else
{
radio.getTag();
radio.setChecked(false);
value=true;
}
}
});
return rowView;
}
}