Search code examples
androidandroid-edittextradio-buttononcheckedchangedischecked

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


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!


Solution

  • 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; 
            } 
          } 
     });