The following are Jave code examples for showing how to use setVisibility() of the android.widget classes. Overriding the View.GONE assignment with the View.INVISIBLE setvisibility android. You can use the examples you like.
Read below to find out about the different options you have to identify the visibility status of a View. A View’s visibility status is of Integer type and can have one of three options.
View.VISIBLE
The View is visible to the user. The integer value for this is 0.
View.GONE
View.GONE makes the view invisible without the view taking up space in the layout. The integer value for this is 8.
View.INVISIBLE
View.INVISIBLE makes the view just invisible still taking up space. The integer value for this is 4.
@Override
public void onStart() {
super.onStart();
final Activity activity = getActivity();
Button button2 = (Button) activity.findViewById(R.id.stranger_button2);
button2.setVisibility(View.GONE);
Button add = (Button) activity.findViewById(R.id.stranger_button1);
if (!checkPending(user)) {
add.setText("Add");
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addUser(user);
getActivity().finish();
}
});
} else {
add.setText("Pending");
}
if (CurrentUserSingleton.getInstance().getUser().getFriends().contains(user)){
Intent intent = new Intent(context, Profile.class);
intent.putExtra("name", user);
startActivity(intent);
getActivity().finish();
}
}
INVISIBLE Vs GONE
The major difference in between the invisible and gone:
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.
The set visibility approach may also allow for easier implementation. For example, if a particular concrete class simply delegates the method to its composite classes, then set visibility means one less method to implement.
Write a comment