0

How do I make a button invisible and when I need it I set the text of the button. Heres the code I tried,This is the MainActivity.class.

 getSupportActionBar().hide();

  phno=(EditText)findViewById(R.id.editText3);

}

public void get(View view){
    String ph=phno.getText().toString();
   Button btn=(Button)findViewById(R.id.button3);
   btn.setText("Call"+ph);
   btn.setTextSize(30);
}

Here's the xml folder:

EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:ems="10"
    android:id="@+id/editText3"
    android:layout_marginTop="119dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:hint="Enter Phone Number"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ok"
    android:id="@+id/button2"
    android:layout_centerVertical="true"
    android:layout_alignRight="@+id/editText3"
    android:layout_alignEnd="@+id/editText3"
    android:onClick="get"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button3"
    android:layout_alignTop="@+id/button2"
    android:layout_alignLeft="@+id/editText3"
    android:layout_alignStart="@+id/editText3"
    android:visibility="gone"
    />

When I enter the number and click Ok, nothing happens. Please help,

AppGeek
  • 137
  • 4
  • 13

2 Answers2

1
btn.setVisibility(VIEW.GONE);  //hide
btn.setVisibility(VIEW.INVISIBLE);//transparent

refer to this for the difference: Android : difference between invisible and gone?

Community
  • 1
  • 1
n3wb
  • 1,037
  • 5
  • 12
  • 20
0
Button btn=(Button)findViewById(R.id.button);
btn.setVisibility(View.GONE);

To hide the button

View.GONE

To transparent view of the button use

View.INVISIBLE
Bruce
  • 8,609
  • 8
  • 54
  • 83