I have a button that basically looks like this:
<Button
android:id="@+id/admin_new_questions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="See Asked Questions"
/>
and I try to display it only in some cases like this:
if ( clause )
{
Button admin_see_questions = (Button)findViewById(R.id.admin_new_questions);
admin_see_questions.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
....
}
});
}
But for some reason, the button is displayed for all cases, but the listenter is not being listened to if the clause is an error.
How can I make the button show up only when the clause is true?
Thanks!
Your button is in the XML layout, so you can hide it or show it by just changing its
visibilityNB: You only need do these operations once:
findViewById()Set the
OnClickListenerof the button–