我正在使用this教程。我有一个带有单选按钮的列表视图。当我点击列表视图值时,所有单选按钮都会更改已检查。我需要单一选择模式,并在单击提交按钮时检查单选按钮列表值。 这是我的onpostexecute
protected void onPostExecute(JSONObject file_url) {
// dismiss the dialog after getting all albums
Log.d("Arraylist: ", "> " + AddressList);
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
if(!AddressList.isEmpty())
{
final ListAdapter adapterlist = new SimpleAdapter(
PlaceEnquiryActivity.this, AddressList,
R.layout.addressscreenlist, new String[] { ADDRESS,
CITY, STATE, COUNTRY }, new int[] {R.id.address,
R.id.city, R.id.state, R.id.country});
// updating listview
setListAdapter(adapterlist);
这是活动中的listview onclick功能
final ListView lv = getListView();
lv.setItemsCanFocus(false);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
RadioButton rb = (RadioButton) v.findViewById(R.id.rb_Choice);
if (!rb.isChecked()) //OFF->ON
{
for (HashMap<String, String> m:AddressList) //clean previous selected
rb.setChecked(true);
//lv.getAdapter().notifyDatasetChanged();
}
}
});
答案 0 :(得分:0)
你犯了错误 for(HashMap m:AddressList)//清除之前选择的
rb.setChecked(true);
//lv.getAdapter().notifyDatasetChanged();
}
使用已检查但未检查的条件。如果未选中,则将其选中。不要使用for循环进行setchecked(true)