안녕하세요 나는 다음과 같은 2 가지 기능을 가지고 있으며 "Positivebutton"을 부울 값에 따라 차단하는 것이 가능한지 궁금해합니다 (사용자가 EditText에 텍스트를 입력했는지 여부).AlertDialog 버튼을 비활성화 하시겠습니까?
private void add() {
final View addView = getLayoutInflater().inflate(R.layout.add, null);
new AlertDialog.Builder(this).setTitle("Add a Book").setView(addView)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
if(addWord((EditText) addView.findViewById(R.id.titleEdit))){
//Do something, Enable the OK (Positive) button
}
else{
Toast.makeText(ActionBarMain.this,"Nothing entered", Toast.LENGTH_LONG).show();
//Prevent the user to be able to push the "PositiveButton" (Block it)
}
}
}).setNegativeButton("Cancel", null).show();
}
private boolean addWord(EditText title){
String mDisplaySting = title.getText().toString();
if(mDisplaySting.matches("")){
Log.i(TAG,"null");
return false;
}
return true;
}
DialogBuilder 개체 ("new AlertDialog.Builder ..."대신 "AlertDialog.Builder b = new ...")를 만들고 if-condition에 양수 버튼을 나중에 추가 하시겠습니까? – Prexx