我不明白为什么会这样.我有以下代码:
AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivityNew.this);
builder.setTitle("Title");
builder.setSingleChoiceItems(R.array.example_arrays,1,null);
builder.setNegativeButton("Cancel",null);
builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Toast.makeText(SettingsActivityNew.this,"which: " + which,Toast.LENGTH_LONG).show();
}
});
builder.show();
出于一些奇怪的原因,int继续给我-1.为什么会这样?
最佳答案
来自doc:
Parameters
dialog The dialog that received the click.
which The button that was clicked (e.g. BUTTON1) or the position of the item clicked.
BUTTON_POSITIVE:
public static final int BUTTON_POSITIVE
Added in API level 3
The identifier for the positive button.
Constant Value: -1 (0xffffffff)
所以这并不奇怪,但完全正常.你每次得到-1因为你点击对话框的positiveButton
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。