getText().toString() not working, returns empty - android

I'm trying to save userName but the saved text file always returns , 6. How can I get it to show whatever value of userName entered into EditText, and the rest? for example Don, 6. I have read you have to use getText() but that isn't returning anything in the saved file.
However, if I replace 6 with an intent to receive score from previous activity, this works! like this...
Bundle extras = getIntent().getExtras();
int score = extras.getInt("Score");
So this becomes...
public void addListenerToEndButton() {
quit = (Button) findViewById(R.id.endBtn);
userName = (EditText) findViewById(R.id.userName);
Bundle extras = getIntent().getExtras();
int score = extras.getInt("score");
quit.setOnClickListener(new View.OnClickListener() {
String strName = userName.getText().toString();
#Override
public void onClick(View v) {
saveProgress(strName + ", " + score, "results.txt");
finish();
System.exit(0);
}
});
}
But it still returns empty, whatever score is. For example , 4.
I've read this post that suggests it should be inside onClickListener which it is:
EditText getText().toString() not working
This is my saveProgress class:
public void saveProgress(String contents, String fileName) {
try {
File fp = new File(this.getFilesDir(), fileName);
FileWriter out = new FileWriter(fp);
out.append(contents);
out.append("\n\r");
out.close();
}
catch (IOException e) {
Log.d("Me","file error:" + e);
}
}

Change your onClick() method with the following:
public void addListenerToEndButton() {
quit = (Button) findViewById(R.id.endBtn);
userName = (EditText) findViewById(R.id.userName);
Bundle extras = getIntent().getExtras();
int score = extras.getInt("score");
quit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String strName = userName.getText().toString();
saveProgress(strName + ", " + score, "results.txt");
finish();
System.exit(0);
}
});
}
Calls, initializations, operations, exc, should go inside the onClick method of the listener. The onClick is fired only when the button is clicked, everything outside the onClick but inside the Listener is called on Listener initialization

I guess you understood 'inside onClickListener' wrong. What you are doing atm is that you read strName when you create the listener, but I guess you want to read it when quit is clicked.
So just move the line into the function and the value will be correct.
public void addListenerToEndButton() {
quit = (Button) findViewById(R.id.endBtn);
userName = (EditText) findViewById(R.id.userName);
quit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String strName = userName.getText().toString();
saveProgress(strName + ", " + 6, "results.txt");
finish();
System.exit(0);
}
});
}

Related

Android SharedPreferences successfully not working

I'm newbie into android and today I wanted to implement some SharedPreferences.
Here's my code: (or Image if ou like it more)
#Override
public void onCreate(Bundle savedInstanceState) {
// SOME CODE HERE
// Initialize Shared Preferences
final SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("MyData", Context.MODE_PRIVATE);
sharedPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
logMsg(sharedPreferences.toString() + "=>" + s + "=>" + sharedPreferences.getString(s, ""));
}
});
final EditText etId = (EditText) findViewById(R.id.etId);
final EditText etValue = (EditText) findViewById(R.id.etValue);
Button btnSave = (Button) findViewById(R.id.btn_save);
btnSave.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
// set Data
logMsg("Id= " + etId.getText().toString() + " Value= " + etValue.getText().toString());
sharedPreferences.edit().putString(etId.getText().toString(), etValue.getText().toString());
if (sharedPreferences.edit().commit()){
logMsg("Success");
}else {
logMsg("Fail");
}
// get Data
logMsg("Id= '" + etId.getText().toString() + "' Value= " + sharedPreferences.getString(etId.getText().toString(), "No Value"));
}
});
//SOME CODE HERE
}
The problem is that after pressing btn_save log says Success on sharedPreferences.edit().commit() but after that I don't retrieve any data with getString() (respectively I retrieve dafault value that is in my case "No Value").
Do you have any idea what's wrong?
Is it necessary to unregister SharedPreferences.OnSharedPreferenceChangeListener?
Thanks.
Each time you call edit(), you get a new instance of SharedPreferences.Editor. You need to do your modifications and commit() (or apply()) on the same editor instance.
Therefore, save the return value of edit() to a variable, and call putString() and commit() on that.

store edited values in edittext fields after changed paramaters

public class ActivityEditParent extends AppCompatActivity {
private static final String TAG="ActivityEditParent";
CustomEditText etFirstName,etLastName,etEmail,etPhone;
public static ConnectionDetector detector;
private static final String URL = "http://hooshi.me.bh-in-13.webhostbox.net/index.php/parents/editprofile";
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
private CustomButton btnSave;
private String parentFirstName,parentLastName,parentPhone;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_parent);
getSupportActionBar().hide();
detector = new ConnectionDetector(ActivityEditParent.this);
getUIComponents();
}
private void getUIComponents(){
etFirstName = (CustomEditText) findViewById(R.id.edit_first_name);
etLastName = (CustomEditText) findViewById(R.id.edit_last_name);
etEmail = (CustomEditText) findViewById(R.id.edit_email_address);
etPhone = (CustomEditText) findViewById(R.id.edit_phone_number);
btnSave = (CustomButton) findViewById(R.id.btn_save_parent);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editParent();
}
});
TextView title = (TextView) findViewById(R.id.toolbar_title);
ImageButton back = (ImageButton) findViewById(R.id.toolbar_back);
title.setText("Edit parent");
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
goBack();
}
});
sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
String fName = sharedPreferences.getString(AppConstants.PARENT_FNAME,AppConstants.fName);
String lName = sharedPreferences.getString(AppConstants.PARENT_LNAME,AppConstants.lName);
String email = sharedPreferences.getString(AppConstants.PARENT_EMAIL,AppConstants.email);
String phone = sharedPreferences.getString(AppConstants.PARENT_MOBILE,AppConstants.mobile);
etFirstName.setText(fName);
etLastName.setText(lName);
etPhone.setText(phone);
etEmail.setText(email);
}
private void goBack() {
startActivity(new Intent(getApplicationContext(), ActivityEditDetails.class));
finish();
}
private void editParent(){
SharedPreferences preferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
JSONObject jsonParam = null;
parentFirstName = etFirstName.getText().toString().trim();
parentLastName = etLastName.getText().toString().trim();
parentPhone = etPhone.getText().toString().trim();
if (detector.checkInternet()){
jsonParam = new JSONObject();
JSONObject header = new JSONObject();
try {
jsonParam.put("parentId",preferences.getString(AppConstants.PARENT_ID,""));
jsonParam.put("parentFN",parentFirstName);
jsonParam.put("parentLN",parentLastName);
jsonParam.put("parentPhone",parentPhone);
jsonParam.put("apiAccessKey",preferences.getString(AppConstants.API_ACCESS_KEY,""));
header.put("parent",jsonParam);
Log.d("POST PARAMETERS:",""+header);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL, header, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.d("Response:",""+response);
String json_status = null;
try {
json_status = response.getString("status");
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
VolleySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectRequest);
}
}
}
In the response After getting success message I want save the edited details in in respective edit text fields please help.After success message I am moving to home screen through intent and again I get back to this screen it is showing the previous details only.
all happens here :
...
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
...
once you have a success response save the edited values on the preferences, for example etFirstName, save it is new value to the corresponding preference :
...
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
editor.putString(AppConstants.PARENT_FNAME, parentFirstName);
editor.apply(); //don't forget this
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
...
any way you're creating the editor but not using it.
you want to save data after download from network or after an edit in edit text fields was made??
if from network add some save method execution statement in code where you download data was successful
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
// here you have successful received data so u can map them to edit text or save in shared prefs
// add method to save data here
saveData(response);
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
private void saveData(JSONObject response) {
// use JSon response object save here to shared preferences
// see how to load data from json object
// https://processing.org/reference/JSONObject_getString_.html
SharedPreferences sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferences.putString(....).apply;
// or set edit text controls with JSon data
}
to save edit text changes you have two choices :
add to layout save button (you have one) button and set on click listener with method to save data:
btnSave = (CustomButton) findViewById(R.id.btn_save_parent);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
saveData(v);
}
});
private void saveData(View view) {
// get root view
View rootView = view.getRootView();
// find edit text widget on root view
EditText etFirstName = (EditText) rootView.findViewById(R.id.edit_first_name);
// get string from edit text widget
String firstName = etFirstName.getString.toString();
// get shared preferences
SharedPreferences sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
// save to shared prefs firstName wher NAME_KEY is string to identified your saved data for later use - to load
sharedPreferences.putString(NAME_KEY,firstName).apply;
}
private void loadDataFromSharedPredferences(View view) {
// get shared preferences
SharedPreferences sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
// load data from shared prefs firstName wher NAME_KEY is string to identified data to load
String firstName = sharedPreferences.getString(NAME_KEY,firstName);
// get root view
View rootView = view.getRootView();
// find edit text widget on root view
EditText etFirstName = (EditText) rootView.findViewById(R.id.edit_first_name);
// set string to edit text widget
etFirstName.setText(firstName);
}
add on text change listener for edittext widgets
ps. you need to clarify - write a exactly steps of what you want to do achieve
load data from network ? then save ?
or save request date ?
or save result data ?

about update data in Android Studio and SQlite

I have 2 questions want to ask about android studio and sqlite.
1) I am trying to run my project in emulator or phone. When I want to return to previous activity by pressing the return button(return function for phone) but it close all my project.But I saw my friend's can return to previous activity by pressing the return button.May I know how and why??
2) I had done update function for my project.The situation is when userA go to "view profile" activity and click edit info, another activity that call "updateinfo" will come out.Then after userA update his information by clicking update button.It's successful update and go back to "view profile" activity to see his updated profile.
But the problem I faced is it does not show out the updated information.It just show a blank "view profile" activity without any information that updated or haven updated.
What should I do?
here my database update function
public boolean updateProfile(String username, String password, String email, String phone)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put (COL_2,username);
values.put(COL_3,password);
values.put(COL_4,email);
values.put(COL_5,phone);
db.update(Table_NAME,values,COL_2 + "=?",new String[]{username});
db.close();
return true;
}
here is my updateinfo activity function
public class EditProfile extends AppCompatActivity {
EditText etEmail,etPhone,etPassword,etConPassword,etUsername;
String password,conpassword,Email,Phone;
Button bUpdate;
DatabaseOperations DB = new DatabaseOperations(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);
etEmail = (EditText) findViewById(R.id.etEmail);
etPhone = (EditText) findViewById(R.id.etPhone);
etPassword = (EditText) findViewById(R.id.etPassword);
etConPassword = (EditText) findViewById(R.id.etConPassword);
etUsername = (EditText) findViewById(R.id.etUsername);
bUpdate = (Button) findViewById(R.id.bUpdate);
Intent i = getIntent();
String email = i.getStringExtra("email");
etEmail.setText(email);
String phone = i.getStringExtra("phone");
etPhone.setText(phone);
String username = i.getStringExtra("username");
etUsername.setText(username);
bUpdate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
password = etPassword.getText().toString();
conpassword = etConPassword.getText().toString();
Email = etEmail.getText().toString();
Phone = etPhone.getText().toString();
if (!(password.equals(conpassword))) {
Toast.makeText(getBaseContext(), "Passwords are not matching", Toast.LENGTH_LONG).show();
etPassword.setText("");
etConPassword.setText("");
etEmail.setText("");
etPhone.setText("");
} else if (etPassword.length() == 0 || etConPassword.length() == 0 || etEmail.length() == 0 || etPhone.length() == 0) {
etPassword.setError("Please complete all information");
etConPassword.setError("Please complete all information");
etEmail.setError("Please complete all information");
etPhone.setError("Please complete all information");
} else if (etPassword.length() < 6) {
etPassword.requestFocus();
etPassword.setError("Password at least 6 characters");
etPassword.setText("");
etConPassword.setText("");
etEmail.setText("");
etPhone.setText("");
} else {
boolean isUpdate = DB.updateProfile(etUsername.getText().toString(),etPassword.getText().toString(),etEmail.getText().toString(),etPhone.getText().toString());
if(isUpdate == true) {
Toast.makeText(getBaseContext(), "Update Success", Toast.LENGTH_LONG).show();
Intent i = new Intent(EditProfile.this, MyProfile.class);
startActivity(i);
finish();
}
else
{
Toast.makeText(getBaseContext(), "Data Not Updated", Toast.LENGTH_LONG).show();
}
}
}
});
}
and here is my viewprofile activity function
public class MyProfile extends AppCompatActivity {
EditText etName,etEmail,etPhone,etShow;
Button bEdit;
String fullname,email,phone;
DatabaseOperations db = new DatabaseOperations(this);
PersonalData profileInfo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_profile);
etName = (EditText) findViewById(R.id.etName);
etEmail = (EditText) findViewById(R.id.etEmail);
etPhone = (EditText) findViewById(R.id.etPhone);
bEdit = (Button) findViewById(R.id.bEdit);
etShow = (EditText) findViewById(R.id.etShow);
fullname = etName.getText().toString();
email = etEmail.getText().toString();
phone = etPhone.getText().toString();
Intent i = getIntent();
String username = i.getStringExtra("username");
etShow.setText(username);
profileInfo = db.getAllinfo(username);
etName.setText(profileInfo.get_name());
etEmail.setText(profileInfo.get_email());
etPhone.setText(profileInfo.get_phone());
bEdit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MyProfile.this,EditProfile.class);
i.putExtra("email", etEmail.getText().toString());;
i.putExtra("phone", etPhone.getText().toString());;
i.putExtra("username", etShow.getText().toString());
startActivity(i);
finish();
}
});
}
you always start new activity and finish the last activity
startActivity(i);
finish();
dont finish it if you want to go back later, you can go back to last activity with finish(); or pressing back in phone
you just need to call finish() when update success (you need to implement answer number 1 first)
Toast.makeText(getBaseContext(), "Update Success", Toast.LENGTH_LONG).show();
Intent i = new Intent(EditProfile.this, MyProfile.class);
startActivity(i);
finish();
in MyProfile make the username variable global
String username;
#Override
protected void onCreate(Bundle savedInstanceState) {
....
username = i.getStringExtra("username");
....
}
last,this code need to be inside onResume()
etShow.setText(username);
profileInfo = db.getAllinfo(username);
etName.setText(profileInfo.get_name());
etEmail.setText(profileInfo.get_email());
etPhone.setText(profileInfo.get_phone());
public boolean update(editProfile.EUsers eusers){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentvalues = new ContentValues();
String username = eusers.getUsername();
String password = eusers.getPassword();
int id = eusers.getId();
contentvalues.put(editProfile.EUsers.COL3_PASSWORD,password);
contentvalues.put(editProfile.EUsers.COL2_USERNAME,username);
int res =db.update(editProfile.EUsers.TABLE_NAME,values,editProfile.EUsers.COL1_ID+" = ?",new String[]{String.valueOf(id)});
if(res >0)
return true;
return false;
}

Android Game Crash (NullPointerException) upon end game [duplicate]

#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.screenlocked);
//Retrieve stored ID
final String STORAGE = "Storage";
SharedPreferences unique = getSharedPreferences(STORAGE, 0);
LoginID = unique.getString("identifier", "");
//Retrieve stored phone number
final String phoneNumber = unique.getString("PhoneNumber", "");
phoneView = (TextView) findViewById(R.id.phone);
phoneView.setText(phoneNumber.toString());
//Retrieve user input
input = (EditText) findViewById(R.id.editText1);
userInput = input.getText().toString();
//Set login button
login = (Button) findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
compareID();
}
});
}
public void compareID(){
if (userInput.equals(LoginID)){
//phone screen unlocked
//continue
Toast.makeText(ScreenLockActivity.this, "Success!", Toast.LENGTH_SHORT).show();
}
else{
count += 1;
input.setText("");
Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
}
}
I am developing a login activity and I would like to record down how many times the user tried to login, so every time there is a login attempt the count will increment by one... but when i run the activity, this error appears in my logcat:
android.content.res.Resources$NotFoundException: String resource ID #0x1,
Can someone help me solve this problem?
Here is your mistake:
Toast.makeText(ScreenLockActivity.this, count, Toast.LENGTH_SHORT).show();
the makeText you are trying to invoke here, is the makeText that takes as second parameter a resId. See here for more info. Since you want to print the count value, you have to convert it in a String.
String value = String.valueOf(count);
Toast.makeText(ScreenLockActivity.this, value, Toast.LENGTH_SHORT).show();
This line should be inside onClick() or compareID():
userInput = input.getText().toString();

How to check empty edittext in android [duplicate]

This question already has answers here:
How do I check if my EditText fields are empty? [closed]
(30 answers)
Closed 9 years ago.
My code does not print empty edit text itry trim stirng .length==00 but is not work hat wrong in my code?? how do my code check if edittext is empty before sumbit query
I want to check before submit method if edittext is empty? If is empty then print toast message
public class AgAppTransPayExternalAccount extends Activity {
TextView lblTPEAWelcomeToPayExternalAccountPage;
TextView lblTPEAOtherAccount;
TextView lblTPEAPinno;
TextView lblTPEAAmount;
EditText txtTPEAotheraccount;
EditText txtTPEApinno;
EditText txtTPEAamount;
Button btnTPEAsubmit;
Button clearTPEAButton;
Button btnTPEAgoback;
String sms;
public static ProgressDialog PayExternalAccountProgressDialog = null;
public static boolean value=true;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agapptranspayexternalaccount);
sms=LoginScreen.item.toString();
/*
lblTPEAWelcomeToPayExternalAccountPage = (TextView)
findViewById(R.id.lblTPEAWelcomeToPayExternalAccountPage);
lblTPEAWelcomeToPayExternalAccountPage.setText("Welcome To Pay External
Account Page");
lblTPEAWelcomeToPayExternalAccountPage.setTextColor(getResources().getColor
(R.color.text_color_black));
*/
lblTPEAOtherAccount = (TextView) findViewById(R.id.lblTPEAOtherAccount);
lblTPEAOtherAccount.setText("Other Account :");
txtTPEAotheraccount=(EditText) findViewById(R.id.txtTPEAotheraccount);
lblTPEAPinno = (TextView) findViewById(R.id.lblTPEAPinno);
lblTPEAPinno.setText("PIN Number :");
txtTPEApinno=(EditText) findViewById(R.id.txtTPEApinno);
lblTPEAAmount = (TextView) findViewById(R.id.lblTPEAAmount);
lblTPEAAmount.setText("Amount :");
txtTPEAamount=(EditText) findViewById(R.id.txtTPEAamount);
btnTPEAsubmit=(Button) findViewById(R.id.btnTPEAsubmit);
btnTPEAsubmit.setTextColor(getResources().getColor(R.color.text_color_blue));
clearTPEAButton=(Button) findViewById(R.id.clearTPEAButton);
clearTPEAButton.setTextColor(getResources().getColor(R.color.text_color_blue));
btnTPEAgoback=(Button) findViewById(R.id.btnTPEAgoback);
btnTPEAgoback.setTextColor(getResources().getColor(R.color.text_color_blue));
clearTPEAButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
txtTPEAotheraccount.setText("");
txtTPEApinno.setText("");
txtTPEAamount.setText("");
}
});
btnTPEAgoback.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
btnTPEAsubmit.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String tpeapinemptycheck = txtTPEApinno.getText().toString();
String otheraccountemptycheck =
lblTPEAOtherAccount.getText().toString();
String amountemptycheck = txtTPEAamount.getText().toString();
if (tpeapinemptycheck.trim().equals("")||
(otheraccountemptycheck.trim().equals("")) ||(amountemptycheck.trim().equals("")))
{
Toast.makeText(getApplicationContext(), "Please Enter
Correct Information", Toast.LENGTH_LONG).show();
}
else
showProgress();
submitPEA();
}
});
}
private void submitPEA() {
String message;
String mobilenumber= LoginScreen.smsmobileno;
if (( sms.compareTo("SMS")==0))
{
SmsManager smsmanager = SmsManager.getDefault();
message="AGPEA"+AgAppHelperMethods.varMobileNo+AgAppHelperMethods.
arMobileNo+txtTPEAotheraccount.getText().toString()+AgAppHelperMethods.
varMobileNo+txtTPEApinno.getText().toString()+txtTPEAamount.getText().toString();
smsmanager.sendTextMessage(mobilenumber, null, message, null, null);
}
else
{
Intent j = new Intent(AgAppTransPayExternalAccount.this, AgAppTransPEAResponse.class);
Bundle bundle = new Bundle();
bundle.putString("txtTPEApinno", txtTPEApinno.getText().toString());
bundle.putString("txtTPEAotheraccount",txtTPEAotheraccount.getText().toString());
bundle.putString("txtTPEAamount",txtTPEAamount.getText().toString());
j.putExtras(bundle);
startActivity(j);
value=false;
PayExternalAccountProgressDialog.dismiss();
}
}
private void showProgress()
{
PayExternalAccountProgressDialog =
ProgressDialog.show(AgAppTransPayExternalAccount.this,null, "Processing please
wait...", true);
if (PayExternalAccountProgressDialog != null) {
try
{
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
#Override
public void run()
{
PayExternalAccountProgressDialog.dismiss();
if(value)
{
Toast.makeText(AgAppTransPayExternalAccount.this, "Request
TimeOut " , Toast.LENGTH_SHORT).show();
}
}
}, 15000); // <--- here is the time adjustment.
}
catch (Exception e)
{
}
}
}
}
Your code is right, only missing this is { } braces in the else condition, try out as following,
if (tpeapinemptycheck.trim().equals("")||
(otheraccountemptycheck.trim().equals("")) ||(amountemptycheck.trim().equals("")))
{
Toast.makeText(getApplicationContext(), "Please Enter
Correct Information", Toast.LENGTH_LONG).show();
}
else
{ // add this
showProgress();
submitPEA();
} // add this
Just because you haven't added those { } braces, your control was going into submitPEA() method.
Try like this
edit_text.getText().toString().trim().equals("");
Create a String variable say x;
Now if et is your EditText field use this:
x = et.getText().toString();
if the EditText field has any text in it it would be passed to the string x.
Now to check if the string x is not null or contains nothing use
if(x.matches(""))
{
//your code here
}
else
{
//the counter action you'll take
}
this way you can check that the entry you are about to enter in the database won't be empty.
Happy coding.

Categories

Resources