Problem description:
Create a button in the program as follows:
[Java]
<Button
Android: id = "@ + id/admin_new_questions"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "See Asked Questions"
/>
<Button
Android: id = "@ + id/admin_new_questions"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "See Asked Questions"
/>
I want this button to only display in some cases:
[Java]
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)
{
....
}
});
}
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)
{
....
}
});
}
If the clause is incorrect, the listener cannot be listened on.
How can I display buttons only when clause is true?
Thank you!
Solution:
[Java]
<Button
Android: id = "@ + id/admin_new_questions"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "See Asked Questions"
Android: visibility = "gone"
/>
If (clause)
{
Button admin_see_questions = (Button) findViewById (R. id. admin_new_questions );
Admin_see_questions.setVisibility (View. VISIBLE );
Admin_see_questions.setOnClickListener (new Button. OnClickListener ()
{
Public void onClick (View v)
{
....
}
});
}
<Button
Android: id = "@ + id/admin_new_questions"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "See Asked Questions"
Android: visibility = "gone"
/>
If (clause)
{
Button admin_see_questions = (Button) findViewById (R. id. admin_new_questions );
Admin_see_questions.setVisibility (View. VISIBLE );
Admin_see_questions.setOnClickListener (new Button. OnClickListener ()
{
Public void onClick (View v)
{
....
}
});
}