【问题标题】:single button with 2 radio buttons with a view of alertdialog带有 2 个单选按钮的单个按钮,带有 alertdialog 视图
【发布时间】:2012-07-14 11:16:47
【问题描述】:

我只想制作一个应该有一个按钮的用户界面,当单击此按钮时,应该会出现一个带有两个可单击单选按钮的对话框。如何制作这样的用户界面?

【问题讨论】:

    标签: android android-ui android-button android-dialog


    【解决方案1】:

    用于创建像这样的警报对话框。在您的按钮单击侦听器中调用此方法。

        private void showDialog() { 
    
    final CharSequence[] Countries = { "India", "U.S.A", "U.K" }; 
    
    AlertDialog.Builder alt_bld = new AlertDialog.Builder(this); 
    alt_bld.setIcon(R.drawable.icon); 
    alt_bld.setTitle("Select Country"); 
    
    //you can set the Default selected value of the list, Here it is 0 means India 
    alt_bld.setSingleChoiceItems(Countries, 0, 
    new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int item) { 
    
    Toast.makeText(getBaseContext(), Countries[item], 
    Toast.LENGTH_LONG).show(); 
    alert.cancel(); 
    } 
    }); 
    
    alert = alt_bld.create(); 
    alert.show(); 
    
    }
    

    【讨论】:

    • 请告诉我如何在该警报对话框中实现 2 个单选按钮
    • 上面的代码有三个单选按钮,例如 India,U.S.A.和英国只要运行这些你就会明白
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多