how to Check Float value Is Null Or not? [duplicate] - android

This question already has answers here:
How do I check if my EditText fields are empty? [closed]
(30 answers)
Does EditText.getText() ever returns null?
(7 answers)
Closed 4 years ago.
I have some EditText which is of "numberDecimal", and One Button. When user clicks on button, data goes to Database. So how to check EditText is empty or not. I am getting error when I try to parse the EditText.

To check an edittext is empty:
EditText ed = (EditText) findViewById(R.id.ed);
age = ed.getText().toString();
if (age.matches("")) {
Toast.makeText(this, "Empty", Toast.LENGTH_SHORT).show();
return;
}
You can also use equals() instead of matches()

Related

How to set range for an editText preference? [duplicate]

This question already has answers here:
Is there a way to define a min and max value for EditText in Android?
(29 answers)
Closed 5 years ago.
I have an editText preference in my Settings Activity.
I want to get a number from 0-99 from the user.
How can i do that?
<EditTextPreference
android:defaultValue="90"
android:key="key_a"
android:inputType="number"
android:title="#string/pref_title"/>
Using this code i have restricted the input to numbers,but i want to further restrict the user from entering more than 2 digits.
If restriction is not possible,any validation method to check if the entered input is <= 99 and if the entered input is invalid, i would like to change the value to its previously saved value.
Adding android:maxLength="2" solved it. Thanks #Suraj Nair

SQLite is not fetching text from TextView [duplicate]

This question already has answers here:
Converting TextView to String (kind of) Android
(2 answers)
Closed 5 years ago.
i am using sqlite and i have some textview in a xml file.The process is to fetch the text from textview and save those in database.But i am unable to fetch text from textview.why?
i.e. it fetches data from editText.
To fetch data from TEXT VIEW use
String text=textViewName.getText().toString();
now you can use the text string and send it to your database

how to change EditText hint color in android [duplicate]

This question already has answers here:
Design Android EditText to show error message as described by google
(7 answers)
Closed 5 years ago.
I have a login
If user don't enter username or password and press "login" button, the EditText hint will warn you, like thislogin(turn red). How can I implement this?
I think you should set error instead
editText.setError(getString(R.string.error_required));
but if you want that
editText.setHint()
editText.setHintTextColor
Based on the image you have posted , it is very simple to show that hint when there is no data entered in username/password fields.
if(username.isEmpty())
{
usernameEditTextView.setHint("please enter username");
usernameEditTextView.setHintTextColor(R.color.Red);
}

removing case senstivity from a string [duplicate]

This question already has answers here:
How do I make my string comparison case-insensitive?
(12 answers)
Closed 6 years ago.
i perform a special action if the string equals something. However, i want to perform the same action if the string has uppercase characters. but i dont want to write so many else if statements for every case-
decrypt
Decrypt
DECRYPT
} else if (message.equals("decrypt")) {
removeencryption(context);
is there a way of removing case sensitivity?
i have already tried
} else if (message.toLowerCase().equals("whistle")) {
whistle(context);
but it is not working
Use equalsIgnoreCase method of String class:
else if (message.equalsIgnoreCase("decrypt")) {
removeencryption(context);
}

On tab key request focus on spinner-Android [duplicate]

This question already has answers here:
Spinner does not get focus
(4 answers)
Closed 10 years ago.
I have a registration form where flow goes as EditText1->EditText2->Spinner->Editext3 ,but on tab press the of EditText2 control is transferred to editText3 and not Spinner How can i do that in android??Can anyone help plz
Use this before your Oncreate()
Spinner spin = (Spinner) findViewById(R.id.spinner1);
spin.setFocusable(true);
spin.setFocusableInTouchMode(true);
spin.requestFocus();

Categories

Resources