Changing textHint of an EditText depending on which radioButton is checked?

845 views Asked by At

I am not sure if it is even possible but if it is I would appreciate your help! I need to change the textHint depending which radioButton is checked Radio Buttons. For example, I want the editText Hint to display "Miles" if the US radioButon is checked; and when the radioButton Metric is checked I want the textHint to display "Kilometers."

I attempted to solve this multiple time but constantly fail.

Tanks ahead of time!

2

There are 2 answers

15
Lal On BEST ANSWER
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1); 
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
     public void onCheckedChanged(RadioGroup group, int checkedId) { 
         // checkedId is the RadioButton selected 
        switch (checkedId) {
            case R.id.radioButtonUS:
                 Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show(); 
                  Distance.setHint("Miles");
                  break; 
            case R.id.radioButtonMetric: 
                  Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show(); 
                 Distance.setHint("Kilometers"); 
                  break; 
        } 
      } 
 });
3
Rogue On

You can use setHint(hint); on your EditText to change the Hint. You can use a listener on your radioButton to detect when one is selected.