gpt4 book ai didi

android - 我正在从列表动态创建复选框,现在如何检查用户从 android 列表中选择了哪个复选框

转载 作者:行者123 更新时间:2023-11-29 20:53:52 27 4
gpt4 key购买 nike

我正在从列表动态创建复选框,现在如何检查用户从 android 列表中选择了哪个复选框

for (int i = 0; i < languageList.size(); i++) {

HashMap<String, String> item_hash = new HashMap<String, String>();
String lang = languageList.get(i).getLanguage();
final String langId = languageList.get(i).getLanguageId();
item_hash.put(langId, lang);

ar[i] = langId;

// String langId = languageList.get(i).getLanguage_id();
item_list1.add(item_hash);
cb = new CheckBox(parentActivity);
cb.setText(languageList.get(i).getLanguage().toString());
cb.setId(Integer.parseInt(languageList.get(i).getLanguageId()));

Button btnSubmit = (Button) findViewById(R.id.btn_submit);

// show location button click event
btnSubmit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {

if(cb.isChecked()){
System.out.println("id "+cb.getText()+langId);

}


}
});
}

最佳答案

也许使用 ListView 会更好。但是,如果您更喜欢使用您需要的方式和复选框数组

ArrayList<CheckBox> cbs = new ArrayList<Checkbox>();
for (int i = 0; i < languageList.size(); i++)
{

HashMap<String, String> item_hash = new HashMap<String, String>();
String lang = languageList.get(i).getLanguage();
final String langId = languageList.get(i).getLanguageId();
item_hash.put(langId, lang);

ar[i] = langId;

// String langId = languageList.get(i).getLanguage_id();
item_list1.add(item_hash);
cb = new CheckBox(parentActivity);
cb.setText(languageList.get(i).getLanguage().toString());
cb.setId(Integer.parseInt(languageList.get(i).getLanguageId()));
cbs.add(cb);

Button btnSubmit = (Button) findViewById(R.id.btn_submit);

// show location button click event
btnSubmit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
for (int i = 0; i < languageList.size(); i++)
if(cbs.get(i).isChecked())
System.out.println("id "+cbs.get(i).getText()+langId);

}
});

关于android - 我正在从列表动态创建复选框,现在如何检查用户从 android 列表中选择了哪个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28315870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com