西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网

AlertDialog默认不选中任何项

时间:2016-02-08 08:30来源:未知 作者:好模板 点击:
setSingleChoiceItems时传入-1即可。 代码如下: private void showKeyWordsDialog(final String answer, final EditText et) { final String[] keywords = (String[])mCurrentItem.getCombinations().toArray(); AlertDialog.Builder builder = n

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();

}
(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(1)
100%
------分隔线----------------------------
栏目列表
热点内容