Search code examples
androidandroid-appwidget

Set android widget visibility dynamycally


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
}

Solution

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