gpt4 book ai didi

java - 处理从可检查菜单中选择的项目

转载 作者:行者123 更新时间:2023-12-01 09:52:33 25 4
gpt4 key购买 nike

我正在使用this创建带有可检查项目的子菜单的教程。到目前为止,一切正常,但我不知道如何处理所选项目,因为我是可序列化的新手。这是教程的链接

https://stackoverflow.com/questions/7072347/how-to-select-multiple-checkboxes-in-submenu-on-android?answertab=active#tab-top

   public static final String SETTING_CHECK_BOX = "SETTING_CHECK_BOX";

private ArrayList < SettingCheckBox > settingList;

@Override
public void onCreate(Bundle savedInstanceState) {
// ...
settingList = new ArrayList < SettingCheckBox > ();
settingList.add ( new SettingCheckBox ( "Option A" ) );
settingList.add ( new SettingCheckBox ( "Option B" ) );
// ... add more items
// restore any previously saved list
if ( savedInstanceState != null ) {
settingList = (ArrayList < SettingCheckBox >) savedInstanceState.getSerializable ( SETTING_CHECK_BOX );
}
// ...
}

protected void onActivityResult ( int requestCode , int resultCode , Intent data ) {
if ( resultCode != RESULT_OK || data == null )
return;
settingList = (ArrayList < SettingCheckBox >) data.getSerializableExtra ( SETTING_CHECK_BOX );

//how can I log print the list of items that have been checked
// What should go here ? such that i can do other things after getting a list of items that were checked ?

//This is my try

Object[] mStringArray = settingList.toArray();

for(int i = 0; i < mStringArray.length ; i++){
Log.d("***Checked items*",(String)mStringArray[i]);
}

}

最佳答案

您从该代码中收到任何错误吗?如果没有,则意味着您的 settingList 已使用 data.getSerializedExtra ( SETTING_CHECK_BOX ); 中的解析值正确初始化,该值是 SettingCheckBox 的列表> 对象。从您提供的链接中,包含 SettingCheckBox 对象类的代码。您对对象内部数据的处理方式取决于您的用例。

<小时/>

编辑:回应评论。

如果名称指的是SettingCheckBox文本描述,您可以直接迭代您的settingList,就像所以:

for(int i = 0; i < settingList.size(); i++){
Log.d("***Checked items*", settingList.get(i).getDescription());
}

关于java - 处理从可检查菜单中选择的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37516992/

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