0

Okay i have one EditText and one spinner. My goal is if item 1 on spinner selected the EditText visibility is true, and if item 2 selected EditText visibility is false. what the code for reach that goal ? i use spiner get selected id like this :

String tipe = spiner.getSelectedItem().toString();
if (tipe=="item2"){
//edittext.visible = false; <-- i don't know how to make/what code this visibility become false
}
user2108272
  • 13
  • 1
  • 1
  • 4

2 Answers2

1

Use the below

if (tipe.equals("item2")){ // .equals to compare strings  
   edittext.setVisibiluty(View.INVISIBLE); //set the visibility
}

Use the below according to your needs

visible   0  Visible on screen; the default value.
invisible 1  Not displayed, but taken into account during layout (space is left for it).
gone      2  Completely hidden, as if the view had not been added.

http://developer.android.com/reference/android/view/View.html#setVisibility(int)

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

use equals() method for comparing of Two String. It will check the content of the String

String tipe = spiner.getSelectedItem().toString();
if (tipe.equals("item2")){
// do what u want here
}
Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50