EditText検証を実行しようとしており、ユーザーが不正な情報を入力したときにAlertDialog を使用したいとします。エラーを通知しても現在のアクティビティを維持するAlertDialog
アラートダイアログが表示され、入力に何が間違っているのかを教えてもらうにはどうすればいいですか?「OK」を押した後、同じビューに戻るだけですか?
「確認」ボタンを検証を行うために押さなどのような活動で ボタンのonClickListenerの内側にすでに午前されるまで、私は待っている:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_progress);
//
// user adds info to progress screen
// clicks confirm when done
//
Button confirmButton = (Button) findViewById(R.id.confirm);
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// do validation code here
//
AlertDialog alert = new AlertDialog.Builder(AddStudentProgress.this).create();
alert.setTitle("Oops");
alert.setMessage("Inputs Can't be Empty");
alert.setButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// I reall want to go back to the Activity and not really do anything
}});
if ((mScoreText.getText().toString().equals(""))) {
alert.show();
}
else {
// validation looks ok, continue
}
私はこれについて間違った道を進んでいますか?私は何をしなければならないのですか?入力を検証したいですか?事前に
おかげで、 マーティン
しかし、私はまだボタンなどを扱っていると思います。 – Martin