I have a listview with radio buttons displaying some items in my android app. I want to have first option selected by default in this listview. Thanks in advance.
当列表视图创建的数组索引为零时,应检查true属性设置,然后您将获得将在列表视图中选择的第一个单选框。
When you override getView()
in your adapter, you could use the position in order to check the first item in your ListView.
RadioButton item;
if (null == view) {
//add code for new view
}
else {
item = (RadioButton) view;
if (position == 0) {
item.setChecked(true);
}
else {
item.setChecked(false);
}
}
This is what I was using as a resource: https://developer.android.com/reference/android/widget/Adapter.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.