Android对话问题

时间:2017-09-05 16:52:20

标签: android dialog double

在我的MainActivity我有2 Buttons来调用2个不同的对话框。第一个效果非常好,但第二个单独替换MainActivity。所以我显示它2次,而不是MainActivity和常规对话窗口。 我不知道为什么代码完全相同:

在MainActivity.java中

第一个对话框的代码:

  public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.action_set: {
                    SetDialog setDialog = new SetDialog(MainActivity.this);
                    setDialog.setContentView(R.layout.settings);
                    setDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    setDialog.show();
                    }

        }

和第二个:

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AddDialog addDialog = new AddDialog(MainActivity.this);
            addDialog.setContentView(R.layout.dialogedit);
            addDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            addDialog.show();
        }
    });

SetDialog.java:

    public class SetDialog extends Dialog  implements android.view.View.OnClickListener {

        Activity a;
        Spinner spinTheme, spinView;
        Button b

utCancel, butApply;

    public SetDialog(Activity c) {
        super(c);
        this.a = c;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        spinTheme =(Spinner) findViewById(R.id.spinnerTheme);
        spinView =(Spinner)findViewById(R.id.spinnerView);
        butApply =(Button)findViewById(R.id.buttonApplySet);
        butCancel = (Button)findViewById(R.id.buttonCancelSet);
    }

    @Override
    public void onClick(View v){}

AddDialog.java:

public class AddDialog extends Dialog implements android.view.View.OnClickListener{
    Activity a;
    Dialog d;
    Button add , cancel;
    RadioButton owes,lent ,money,things ;
    EditText name ,amount,object,note;
    Spinner spin;

public AddDialog(Activity c) {
    super(c);
    this.a = c;
}

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    a.setContentView(R.layout.dialogedit);
    add=(Button)a.findViewById(R.id.buttonAdd);
    cancel=(Button)a.findViewById(R.id.buttonCancel);
    owes = (RadioButton) a.findViewById(R.id.radioButtonOwes);
    lent = (RadioButton) a.findViewById(R.id.radioButtonLent);
    money = (RadioButton)a.findViewById(R.id.radioButtonAmount);
    things =(RadioButton) a.findViewById(R.id.radioButtonThings);
    name = (EditText) a.findViewById(R.id.editName);
}

@Override
public void onClick(View v){
};}

1 个答案:

答案 0 :(得分:0)

你做

setContentView(R.layout.dialogedit)

从而将布局设置为您的活动主视图。而是做

Error: [$injector:unpr] Unknown provider: userProvider <- user