服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #

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%
------分隔线----------------------------
栏目列表
热点内容