Android技术知识

[Android]AlertDialog默认不选中任何项

2015-12-22  本文已影响1163人  GingerBot

setSingleChoiceItems时传入-1即可。
代码如下:

private void showKeyWordsDialog(final String answer, final EditText et) {
    final String[] keywords = (String[])mCurrentItem.getCombinations().toArray();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    DialogInterface.OnClickListener onWorDClicked = new DialogInterface.OnClickListener(){

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            String word = keywords[which];
            et.setText(word);
        }
    };

    builder.setTitle("请选择正确答案");
    builder.setIcon(R.drawable.ic_launcher);
    builder.setSingleChoiceItems(keywords, -1, onWorDClicked);
    builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    mKeywordsDialog = builder.create();
    mKeywordsDialog.show();

}
上一篇 下一篇

猜你喜欢

热点阅读