"how to have radio button in listview" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "how to have radio button in listview" answered properly. Developers are finding an appropriate answer about how to have radio button in listview related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like how to have radio button in listview. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on how to have radio button in listview.
how to have radio button in listview
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// I do no use these values anywhere inside the ArrayAdapter. I could, but don't.
final Integer[] values = new Integer[] {1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,};
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this, R.layout.row, R.id.textview, values) {
int selectedPosition = 0;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
RadioButton r = (RadioButton)v.findViewById(R.id.radiobutton);
}
TextView tv = (TextView)v.findViewById(R.id.textview);
tv.setText("Text view #" + position);
RadioButton r = (RadioButton)v.findViewById(R.id.radiobutton);
r.setChecked(position == selectedPosition);
r.setTag(position);
r.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
selectedPosition = (Integer)view.getTag();
notifyDataSetChanged();
}
});
return v;
}
};
setListAdapter(adapter);
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on how to have radio button in listview can get a collection of related answers to their query. Programmers need to enter their query on how to have radio button in listview related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to have radio button in listview for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of how to have radio button in listview while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "how to have radio button in listview". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to have radio button in listview resolved professionally and stay updated to the latest Whatever updates.