4

How to set text programmatically for EditText control when its inputType is number ?

<EditText
    android:id="@+id/WorkingHoursET"
    android:layout_width="fill_parent"
     android:textColor="@color/white"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/WorkingHoursTV"
    android:layout_below="@+id/WorkingHoursTV"
    android:layout_marginTop="14dp"
    android:ems="10"
    android:inputType="number" />


    EditText workedHours = (EditText)findViewById(R.id.WorkedHoursET);
    workedHours.setText(8); //this is not working
    workedHours.setText("8"); //neither this
1
  • 3
    i guess this is because you are passing wrong id WorkedHoursET insteaD OF WorkingHoursET Commented Sep 16, 2013 at 13:38

1 Answer 1

4

Try with

workedHours.setText("8", BufferType.EDITABLE);

If you check the docs for EditText, you'll find a setText() method. It takes in a String and a TextView.BufferType.


NOTE : As Shailendra Singh Rajawat noted you might using wrong id of EditText. You should look into that too. That code should be

EditText workedHours = (EditText)findViewById(R.id.WorkingHoursET);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.