死代码 android setMultiChoiceItems
我使用 setMultiChoiceItems 作为对话框中的列表。 当单击“确定”时,代码是
.setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
String[] res = null;
for(int i=-1,l=usrCats.length; ++i<l;){
if(selections[i])
res[i] = usrCats[i].toString();
}
if(res != null && res.length>0)
dbManager.removeUserShoppingCategories(res);
}
})
我想检查是否使用 if(selections[i]
选择了某个项目,如果是,请将名称添加到 String
i 在 res[i] = usrCats[i].toString()
中具有空指针访问权限,并且在最后一个 if 语句中出现死代码警告。
我正在使用最后一个 if 来检查是否有任何选择以便调用我的方法。
我做错了什么?
i use setMultiChoiceItems for a list in a dialog.
when click on ok the code is
.setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
String[] res = null;
for(int i=-1,l=usrCats.length; ++i<l;){
if(selections[i])
res[i] = usrCats[i].toString();
}
if(res != null && res.length>0)
dbManager.removeUserShoppingCategories(res);
}
})
i want to check if an item is selected with if(selections[i]
and if so, add the name in a
String
i am having a null pointer access in the res[i] = usrCats[i].toString()
and a dead code warning in the last if statement.
i am using the last if, to check if there has been any selection so as to call my method.
what am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)