Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting initial Edittext value to blank on focus
    primarykey
    data
    text
    <p>I have 4 edit text fields in my app which take in one long and 3 double values respectively. I have used them with onFocusChangedListener(). My issue is whenever a certain edit text gains focus a default (0.0 in case of double) is displayed into the edit field before the user enters the values. I want them to to be blank before the user enters his values. I have tried using editText.setText("") and editText.setHint(""). But these work when the activity starts, but once the edit field gains focus the default values are shown. Please help me with the glitches. Thank you.</p> <p>Heres the code</p> <pre><code>public void onFocusChange(View EditTextFocus , boolean hasFocus) { // TODO Auto-generated method stub try { km= Long.parseLong(ETKm.getText().toString()); fuelQty= Double.parseDouble(ETFuelQty.getText().toString()); fuelPrice= Double.parseDouble(ETFuelPrice.getText().toString()); totalCost= Double.parseDouble(ETTotalCost.getText().toString()); } catch(NumberFormatException ne) { ne.printStackTrace(); } if(ETTotalCost.hasFocus()) { if((fuelQty!=0)&amp;&amp;(fuelPrice!=0)) totalCost=fuelQty*fuelPrice; ETTotalCost.setText(new DecimalFormat("##.##").format(totalCost)); } else if(ETFuelQty.hasFocus()) { ETFuelQty.setText(""); if((fuelPrice!=0)&amp;&amp;(totalCost!=0)) fuelQty= (int) (totalCost/fuelPrice); ETFuelQty.setText(String.valueOf(fuelQty)); } else if(ETFuelPrice.hasFocus()) { ETFuelPrice.setText(""); if((fuelQty!=0)&amp;&amp;(totalCost!=0)) fuelPrice=totalCost/fuelQty; ETFuelPrice.setText(String.valueOf(fuelPrice)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload