如何在android中的自定义对话框中打开自定义对话框

时间:2014-06-09 09:14:58

标签: android dialog

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

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


              }
            });

1 个答案:

答案 0 :(得分:0)

根据Android nested AlertDialog - is this possible?

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

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

在Dialog中单击监听器代码,将活动作为

启动
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 dialogAlertDialog inside alertdialog android