-4

I am developing an android app. Here I need to set values in some EditText. Then I have to clear all. How can I do this? The EditData.java code are given below:

    morning = (EditText) findViewById(R.id.morning);
    noon = (EditText) findViewById(R.id.noon);
    afternoon = (EditText) findViewById(R.id.afternoon);
    night = (EditText) findViewById(R.id.night);
    before_meal = (EditText) findViewById(R.id.before_meal);
    after_meal = (EditText) findViewById(R.id.after_meal);
    hourly = (EditText) findViewById(R.id.hourly);
    days = (EditText) findViewById(R.id.days);

    morning.setText(String.valueOf(scheduleTime.charAt(0)));

    noon.setText(String.valueOf(scheduleTime.charAt(1)));

    afternoon.setText(String.valueOf(scheduleTime.charAt(2)));

    night.setText(String.valueOf(scheduleTime.charAt(3)));

    before_meal.setText(String.valueOf(scheduleTime.charAt(4)));

    after_meal.setText(String.valueOf(scheduleTime.charAt(5)));

    hourly.setText(String.valueOf(scheduleTime.charAt(6)));

    days.setText(String.valueOf(scheduleTime.charAt(7)));
Md Khairul Islam
  • 597
  • 5
  • 14

2 Answers2

3

Add this code to clear all your editText :

    morning.setText("");

    noon.setText("");

    afternoon.setText("");

    night.setText("");

    before_meal.setText("");

    after_meal.setText("");

    hourly.setText("");

    days.setText("");
Imene Noomene
  • 3,035
  • 5
  • 18
  • 34
1

you can do by below mentioned ways

1) myEditText.setText("");

2)Where clear is registered as onclick handler for the button in the layout file like this

<ImageButton android:id="@+id/ClearButton"
    android:text="@string/ClearButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="clear"           <<<--------here
    android:src="@drawable/clear"
/>
Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58