やあみんな私はActivity
いくつかのEditText
フィールドを持っています。
ユーザーは、保存を押す前にすべてのテキスト フィールドに入力する必要がありますButton
。
これが私がうまくいくと思ったものです。フィールドに入力されたテキストを確認しましたEditText
。テキストが null でない場合は、それぞれのデータがデータベースに保存されますが、テキストが null の場合は、テキストToast
を再入力するようにメッセージが表示されます。コードは次のとおりです。
account_Number.setText(null);
customer_Number.setText(null);
account_Holder.setText(null);
bank_Name.setText(null);
branch_Name.setText(null);
branch_Address.setText(null);
Ifsc.setText(null);
Micr.setText(null);
current_Balance.setText(null);
AddAccount = (Button) findViewById(R.id.addAccount);
AddAccount.setOnClickListener(this);
}
// only after all the fields have been filled, should the message data added
// successfully be displayed.
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.addAccount:// try making the user enter in all the fields
boolean work = true;
if (account_Number.getText() != null
&& customer_Number.getText() != null
&& account_Holder.getText() != null
&& bank_Name.getText() != null
&& branch_Name.getText() != null
&& branch_Address.getText() != null
&& Ifsc.getText() != null && Micr.getText() != null
&& current_Balance.getText() != null) {
try {
String accountNumber = account_Number.getText().toString();
String customerNumber = customer_Number.getText()
.toString();
String accountHolder = account_Holder.getText().toString();
String bankName = bank_Name.getText().toString();
String branchName = branch_Name.getText().toString();
String branchAddress = branch_Address.getText().toString();
String ifsc = Ifsc.getText().toString();
String micr = Micr.getText().toString();
String currentBalance = current_Balance.getText()
.toString();
DatabaseClass entry = new DatabaseClass(AddnewAccount.this);
entry.open();
entry.createEntry(accountNumber, customerNumber,
accountHolder, bankName, branchName, branchAddress,
ifsc, micr, currentBalance);
} catch (Exception e) {
work = false;
Dialog message = new Dialog(this);
message.setTitle("Error");
String error = e.toString();
TextView tv = new TextView(this);
tv.setText(error);
message.setContentView(tv);
message.show();
} finally {
Toast message = Toast.makeText(AddnewAccount.this,
"Data Added Successfully", Toast.LENGTH_SHORT);
message.show();
Intent goBackHome = new Intent(AddnewAccount.this,
AccountManagerActivity.class);
startActivity(goBackHome);
finish();
}
} else {
Toast message = Toast.makeText(AddnewAccount.this, // not getting executed
"Please Fill All The Fields", Toast.LENGTH_LONG);
message.show();
Intent refill = new Intent(AddnewAccount.this,
AddnewAccount.class);
startActivity(refill);
finish();
}
break;
}
}