ListView SimpleAdapter设置RadioButton选中unChecked

时间:2014-07-16 10:53:05

标签: android android-layout listview android-listview

我在列表视图中有一个RadioButton我从服务器获取数据并分配给ListView但在列表视图中有一个RadioButton如何分配签入RadioButton

代码:

for(int i=0;i<..........)
{
    HashMap<String, String> map = new HashMap<String, String>();
    map.put(ID,(((Node) node_list_variables.getDoc_id().item(0)).getNodeValue()));
    map.put(ANSWER, (((Node) node_list_variables.getAnswer().item(0)).getNodeValue()));
    map.put(QUESTION_ID, (((Node) node_list_variables.getQuestion_id().item(0)).getNodeValue()));
    map.put(DESCRIPTION, i+1+", "+(((Node) node_list_variables.getQuestion().item(0)).getNodeValue()));

    menuItems.add(map);
}

// Adding menuItems to ListView
// All filed data are not shown in the list KEY_ID is hidden
ListAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.certification_question_item,
new String[] { DESCRIPTION, QUESTION_ID, ANSWER, ID }, 
new int[] {R.id.questionText, R.id.question_id, R.id.answer });
setListAdapter(adapter);

R.id.answer是我的单选按钮组ID

1 个答案:

答案 0 :(得分:0)

为什么不直接使用ArrayAdapter?

    View layout = inflater.inflate(R.layout.whatever_you_called_your_layout_file, (ViewGroup)findViewById(R.id.whatever_you_called_your_layout_if_its_not_already_inflated));
    ListView theList = (ListView)layout.findViewById(R.id.whatever_you_called_the_listview);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, android.R.id.text1, theNameOfTheStringArrayContainingYourValues);
    theList.setAdapter(adapter);
    theList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    theList.setItemChecked(checkedItem, true);

确保已将int checkedItem设置为String []中索引的值,以便检查要检查的项目。