【问题标题】:Java Android - Radio Button not showingJava Android - 单选按钮未显示
【发布时间】:2017-05-24 15:56:39
【问题描述】:

我创建了两个单选按钮:

  • 首先,蓝牙
  • 其次,用于 RS232

但我的应用程序只显示其中一个。

这是我的代码:

final RadioButton Bluetooth = new RadioButton(this);
Bluetooth.setId(TEXT_ID);
alertDialogBuilder.setView(Bluetooth);
Bluetooth.setText("Bluetooth");
Bluetooth.setTextSize(20);

final RadioButton RS232 = new RadioButton(this);
RS232.setId(TEXT_ID);
alertDialogBuilder.setView(RS232);
RS232.setText("RS232");
RS232.setTextSize(20);

【问题讨论】:

  • 请也分享您的布局xml!
  • 抱歉,我没有 XML。目的是在警报对话框中添加两个 RadioButton。当用户单击项目菜单时会显示警报对话框。

标签: java android radio-button


【解决方案1】:

使用此代码来定义您的警报对话框。 创建一个包含两个单选按钮的 xml 布局,然后在 java 中在警报对话框中制作视图和膨胀视图。

                View view2 = View.inflate(MyActivity.this, R.layout.radiobutton, null);

                AlertDialog.Builder builderconversion = new AlertDialog.Builder(MyActivity.this);
                //builder1.setMessage("Radio Message");
                builderconversion.setView(view2);
                builderconversion.setCancelable(true);
                builderconversion.setPositiveButton("CLOSE",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {

                                //Methods and functions
                                dialog.cancel();
                            }
                        });

                AlertDialog alertconversion = builderconversion.create();
                alertconversion.show();

【讨论】:

  • 感谢您的帮助。我将在布局目录中创建一个新的 XML 文件。我会看看,如果它的工作。
猜你喜欢
  • 2014-08-22
  • 2016-10-29
  • 2015-12-16
  • 1970-01-01
  • 1970-01-01
  • 2013-04-26
  • 1970-01-01
  • 2014-05-25
相关资源
最近更新 更多