1
votes

I have an EditText field with inputType numberDecimal. I found the field in my code:

EditText mField = (EditText) v.findViewById(R.id.fieldName);

I want to set this field value before rendering. I tried to setText(), application crashed because I can't set string value on a field of type numberDecimal.

Edit: I need an input field with KeyListener contains only numbers and dot, also I want to can pass default double/float/int value.

Answer: I was using wrong field id.

1
Can you post the actual code where you are setting the value into edit text? I guess you might be making some mistake while parsing the value. Be mindful, it accepts only charsequence. - LoveForDroid
I'm trying something like that: mField.setText(String.valueOf(230.3)); @LoveForDroid - user3574298
Can you check and post the crash error message from your logcat. Also mention to which line in your code, is it pointing. - LoveForDroid
Passing float/double it doesn't crash but neither shows the value(edit: passing String.valueOf(float/double) ). If I cast this to int is trying to find a resource android.content.res.Resources$NotFoundException: String resource ID #0xc8 @LoveForDroid - user3574298
Error:(38, 14) error: no suitable method found for setText(double) method TextView.setText(CharSequence) is not applicable (argument mismatch; double cannot be converted to CharSequence) method TextView.setText(int) is not applicable (argument mismatch; possible lossy conversion from double to int) @LoveForDroid - user3574298

1 Answers

0
votes

If you have to just hardcode the value, on screen load, why don't you just do this:

mField.setText("230.3");

mField.setOnEditorActionListener(new EditText.OnEditorActionListener() 
        {
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) 
            {
                if (i == EditorInfo.IME_ACTION_DONE) 
                {
                    // Done button pressed
                }
                return false;
            }
        });