質問

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
}
役に立ちましたか?

解決

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)

他のヒント

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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top