saving data of EDITTEXT field in
I have two user screens in my app. In the first screen i have two EditText
fields. One takes a string and another an int. I click on the save button to save the values in the database. now the problem that i get is that NULL
is being saved into the database. when I hard code it, the values get saved. Anyone has any idea as to why is this ha开发者_Go百科ppening.
this is what i am trying to do with code:
EditText userNameTextField = (EditText)findViewById(R.id.savehighscoresid);
userNameString = userNameTextField.getText().toString();
if (userNameTextField.getText().toString().length() != 0) {
value = String.valueOf(userNameTextField.getText());
}
Try this..Where value is String..
Check if userNameTextField.getText().toString() == null;
. If yes, disable your save button. Add a textChangedListner to check if text is getting added in that box
userNameTextField.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
charachtercounter1.setText(String.valueOf(s.length()));
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
精彩评论