I am trying to simply get a button to vanish into the distance upon click. Here is my code. What is wrong?
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button mainButton1=(Button)findViewById(R.id.mainButton1);
mainButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Button button = (Button) v;
button.setVisibility(View.INVISIBLE);
}
});
}
}
In case are you try to hide mainButton1, Try this code.
public class MainActivity extends Activity
{
Button mainButton1 ;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainButton1=(Button)findViewById(R.id.mainButton1);
mainButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Button button = (Button) v;
mainButton1.setVisibility(View.GONE);
}
});
}
}
difference between gone and invisible
INVISIBLE:
This view is invisible, but it still takes up space for layout purposes.
GONE:
This view is invisible, and it doesn't take any space for layout purposes.