Radio button in view list?

I have a scenario in which we should have a select mode select switch in the list. when I click on the radio camera, it should go into the on state. when I click on the whole element, then it should redirect to a new activity. I referred below to the link

link1 , link2

I can find a way for multiple selection mode. but not for single select mode. Any idea on this?

??? Edit??? How can I find the tag of the corresponding element tag in listview

+4
source share
2 answers

One way you can, but I don't know if this is perfect or not.

track the identifier of the position of the list on which the switch was set when you click on another switch, then implement setOnCheckedChangeListener(listener) and check the position that has already been checked, and uncheck this radio book.

You can save the switch status in a user model (Model, which contains controls such as textview, imageview, radioobutton, etc. for one line of the list) that has been added to the list

check this article to use the model and process the component in the list in this example check box example

Update

I think you can get the tag this way

 ((View)((ViewGroup)listview.getItemAtPosition(0)).getTag()).getTag(); or ((Button)l.getItemAtPosition(0)).getTag(); 

update 2

suppose this is your adapter and arraylist object

 private List<Model> list_model = new ArrayList<Model>(); private ArrayAdapter<Model> modelAdapter; 

you class Model is as follows

 private class Model{ private String text1 = ""; private boolean isChecked = false; public Model(String text1){ this.text1 = text1; isChecked = false; } } 

your viewer

 private static class ViewHolder{ TextView textView; RadioButton radioBtn; } 

pass listmodel to this CustomAdapter class in the constructor

 private List<Model> list; private Context context; public CustomAdapter(Context context, List<Model> list){ super(context,R.layout.list_layout,list); this.list = list; this.context = context; } 

now in getView()

 @Override public View getView(int position, View convertView, ViewGroup parent) { View view = null; if(convertView == null){ LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.gcalendar_list_layout, null); final ViewHolder viewHolder = new ViewHolder(); viewHolder.textView = (TextView) view.findViewById(R.id.text1); viewHolder.radioBtn = (RadioButton) view.findViewById(R.id.radioBtn); viewHolder.radioBtn.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Model element = (Model) viewHolder.checkBox.getTag(); element.isChecked = buttonView.isChecked(); boolean isChecked = true; for(int i=0;i<list.size();i++){ if(!list.get(i).isChecked){ list.get(i).isChecked=false; // more implement here or may be this work break; } } } }); view.setTag(viewHolder); viewHolder.radioBtn.setTag(list.get(position)); }else{ view = convertView; ((ViewHolder)view.getTag()).radioBtn.setTag(list.get(position)); } ViewHolder holder = (ViewHolder) view.getTag(); holder.textView.setText(list.get(position).name); holder.radioBtn.setChecked(list.get(position).isChecked); return view; } 
+4
source

When there is only one widget of choice, this is a CheckBox. You will have to adjust the list a bit in your adapter - you will need to register a custom event listener when setting up list views, and keep in mind that these views are reused (or create new views if you don't care about performance)

0
source

All Articles