【问题标题】:how to open custom dialog box in a custom dialog box in android如何在android的自定义对话框中打开自定义对话框
【发布时间】:2014-07-29 19:20:08
【问题描述】:

我的应用程序在按钮单击时包含一个自定义对话框,其中我有一些复选框可以选择其中一个复选框,它会显示另一个带有 3 个复选框的对话框,请帮助我 这是我打开第一个对话框的代码

ImageView img1 = (ImageView)findViewById(R.id.image_menu);
        img1.setOnClickListener(new OnClickListener() {

              @Override
              public void onClick(View arg0) {

                // custom dialog
                final Dialog dialog = new Dialog(MainActivity.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.menu);

                Button dialogButton = (Button) dialog.findViewById(R.id.btncross);
                // if button is clicked, close the custom dialog
                dialogButton.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });

                 dialog.show();
                 Spinner spin = (Spinner)dialog.findViewById(R.id.spinState);
                 ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(MainActivity.this,  android.R.layout.simple_spinner_item, states);
                 adapter_state.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                 spin.setAdapter(adapter_state);
                 spin.setSelection(pos);
                 spin.setOnItemSelectedListener(MainActivity.this);



                 Button btnShare = (Button)dialog.findViewById(R.id.btnShare);
                 btnShare.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
                        sharingIntent.setType("text/plain");
                        String shareBody = "Dry Day App ";
                        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "DryDayApp");
                        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
                        dialog.getContext().startActivity(Intent.createChooser(sharingIntent, "Share via"));

                    }

                 });


                 cb1 = (CheckBox)dialog.findViewById(R.id.checkBoxHR);
                 cb1.setOnCheckedChangeListener(listener1);

                 cb2 = (CheckBox)dialog.findViewById(R.id.checkBoxDay);
                 cb2.setOnCheckedChangeListener(listener2);

                 cb3 = (CheckBox)dialog.findViewById(R.id.checkBox1);
                 cb3.setOnCheckedChangeListener(listener3);

                 preferences = getSharedPreferences("syllabus", 0);
                 cb1.setChecked(preferences.getBoolean("c1" ,false));
                 cb2.setChecked(preferences.getBoolean("c2" ,false));
                 cb3.setChecked(preferences.getBoolean("c3" ,false));


              }
            });

【问题讨论】:

    标签: android dialog


    【解决方案1】:

    根据Android nested AlertDialog - is this possible?

    只需设计一个新的 xml 布局作为您的对话框并创建一个新活动并将其主题设置为清单文件中活动标记 ex 下的 @android:style/Theme.Dialog:

    <activity android:theme="@android:style/Theme.Dialog" android:name="LocationDialog"> </activity>
    

    在Dialog中点击监听代码启动activity为

    new AlertDialog.Builder(ActivityMain.this).setMessage(
      "Are you sure?").setPositiveButton("Yes",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface arg0, int arg1) {
                 Intent i = new Intent(YourActivity.this, NewActivity.class);
                 startActivity(i);
          }
    

    这会将您的新活动作为一个对话框启动,您可以在其中轻松应用您的操作。

    //编辑 你应该阅读Android display another dialog from a dialog和AlertDialog inside alertdialog android

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多