0
在此之前是標記爲重複或垃圾郵件我想你知道,我已經嘗試了以前的問題的所有答案,但毫無效果無法取消AlertDialog
我有一個AlertDialog,我想在失敗的情況下被解僱。因此,這裏是我的代碼:
private AlertDialog openPinDialog() {
builder = new AlertDialog.Builder(MainActivity.this);
View view = getLayoutInflater().inflate(R.layout.dialog_layout, (ViewGroup)findViewById(R.id.rootLayout));
one = (Button)view.findViewById(R.id.button);
two = (Button)view.findViewById(R.id.button2);
three = (Button)view.findViewById(R.id.button3);
four = (Button)view.findViewById(R.id.button4);
five = (Button)view.findViewById(R.id.button5);
six = (Button)view.findViewById(R.id.button6);
seven = (Button)view.findViewById(R.id.button7);
eight = (Button)view.findViewById(R.id.button8);
nine = (Button)view.findViewById(R.id.button9);
zero = (Button)view.findViewById(R.id.buttonzero);
image1 = (ImageView)view.findViewById(R.id.imageView);
image2 = (ImageView)view.findViewById(R.id.imageView2);
image3 = (ImageView)view.findViewById(R.id.imageView3);
image4 = (ImageView)view.findViewById(R.id.imageView4);
tv = (TextView)view.findViewById(R.id.changeText);
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
four.setOnClickListener(this);
five.setOnClickListener(this);
six.setOnClickListener(this);
seven.setOnClickListener(this);
eight.setOnClickListener(this);
nine.setOnClickListener(this);
zero.setOnClickListener(this);
builder.setView(view);
builder.setTitle("Master Password");
return builder.create();
}
,我想它被辭退:
private void retypePassword(){
checkPinCode.append(String.valueOf(buttonClicked.getText()));
if (count == 5){
image1.setImageResource(R.drawable.ic_lens_black_24dp);
}else if (count == 6){
image2.setImageResource(R.drawable.ic_lens_black_24dp);
}else if (count == 7){
image3.setImageResource(R.drawable.ic_lens_black_24dp);
}else if (count == 8){
image4.setImageResource(R.drawable.ic_lens_black_24dp);
checkPinCode = checkPinCode.delete(0,4);
pinCode = pinCode.delete(4,8);
Log.e("1st Try", pinCode.toString());
Log.e("2nd Try", checkPinCode.toString());
if (checkPinCode.toString().equals(pinCode.toString())){
tv.setText(R.string.second_text);
Toast.makeText(MainActivity.this, "Pins match", Toast.LENGTH_SHORT).show();
}else {
if (openPinDialog() != null && openPinDialog().isShowing()){
openPinDialog().dismiss();
}
tv.setText(R.string.first_text);
Toast.makeText(MainActivity.this, "Pins don't match", Toast.LENGTH_SHORT).show();
count = 0;
image1.setImageResource(R.drawable.ic_radio_button_unchecked_black_24dp);
image2.setImageResource(R.drawable.ic_radio_button_unchecked_black_24dp);
image3.setImageResource(R.drawable.ic_radio_button_unchecked_black_24dp);
image4.setImageResource(R.drawable.ic_radio_button_unchecked_black_24dp);
pinCode.delete(0, pinCode.length());
checkPinCode.delete(0, checkPinCode.length());
}
}
}
onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
openButton = (Button)findViewById(R.id.button10);
openButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPinDialog();
}
});
pinCode = new StringBuffer();
checkPinCode = new StringBuffer();
}
結果:
'視圖視圖= LayoutInflater.from(builder.getContext())。膨脹(R.layout.dialog_layout,NULL,假);'使用對話框構建器的上下文進行適當的主題化,對話框還沒有根視圖。 –