0
在我的MainActivity
中我有2個Buttons
來調用2個不同的對話框。第一個工作得很好,但第二個自己替換MainActivity
。所以我顯示了它2次,而不是MainActivity
,並在常規的對話窗口中顯示。 我不知道爲什麼會是這樣的代碼是完全一樣的:Android對話框問題
在第一個對話框的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){
};}
是的,這可能是所有其他「一」的,你應該刪除這些也相同。如果這能解決它,你可能想接受我的答案。 – Frank