2 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
我們需要這樣做以禁止用戶輸入空值作為文件名。除非 userInput 不為空,否則應(yīng)禁用保存按鈕。
這是當(dāng)前代碼:
public void openDialog() {
@SuppressLint("InflateParams") View view = (LayoutInflater.from(AudioRecorder.this)).inflate(R.layout.audio_name_input, null);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(AudioRecorder.this);
alertBuilder.setView(view);
final EditText userInput = view.findViewById(R.id.userInput);
alertBuilder.setCancelable(true);
alertBuilder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
inputName = String.valueOf(userInput.getText());
Toast.makeText(AudioRecorder.this, "Next audio clip will be named... " + inputName, Toast.LENGTH_SHORT).show();
filePathMaking();
}
});
alertBuilder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
Dialog dialog = alertBuilder.create();
dialog.show();
}

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊
添加一個(gè)TextChangedListener
到編輯文本。通過用戶輸入啟用或禁用按鈕。
dialog.getButton(AlertDialog.BUTTON1).setEnabled(false);
您可以像和一樣訪問肯定按鈕
添加回答
舉報(bào)