Show And Hide Drop Down List On Button Click?
I am using a button and on clicking it ,a drop down list opens and the arrow sign changes.but I want to hide the drop down list on button's click again.mean to show and hide altern
Solution 1:
You can use boolean.
Lets say..
boolean isButton=true;
protectedvoidonCreate(Bundle savedInstanceState) {
myphotosBtn=(Button)findViewById(R.id.myPhotosBtn);
myphotosBtn.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
if(isButton){
arrowDown.setImageResource(R.drawable.arrow_up);
findViewById(R.id.dropdownList).setVisibility(View.VISIBLE);
isButton=false;
}else{
arrowDown.setImageResource(R.drawable.down);
findViewById(R.id.dropdownList).setVisibility(View.GONE);
isButton=true;
}
}
});
Solution 2:
Try this:
protectedvoidonCreate(Bundle savedInstanceState) {
myphotosBtn=(Button)findViewById(R.id.myPhotosBtn);
Boolean temp=false;
myphotosBtn.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
if(temp){
arrowDown.setImageResource(R.drawable.arrow_down);
findViewById(R.id.dropdownList).setVisibility(View.GONE);
temp=false;
}else{
arrowDown.setImageResource(R.drawable.arrow_up);
findViewById(R.id.dropdownList).setVisibility(View.VISIBLE);
temp=true;
}
}
});
Take this as a reference and develop your logic.
Another way to implement this is, Use CheckBox instead of Button, and write onChecked method code. You can achieve this using it also.
Solution 3:
boolean isshow=false;
protectedvoidonCreate(Bundle savedInstanceState) {
myphotosBtn=(Button)findViewById(R.id.myPhotosBtn);
myphotosBtn.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
if(!isshow)
arrowDown.setImageResource(R.drawable.arrow_up);
findViewById(R.id.dropdownList).setVisibility(View.VISIBLE);
isshow=true;
} else {
arrowDown.setImageResource(R.drawable.arrow_up);
findViewById(R.id.dropdownList).setVisibility(View.INVISIBLE);
isshow=false;
}
});
You can use sharedpreferences
to store booolean variable value.
Solution 4:
I know this question is already answered, but if you might stumble upon this looking for a dropdown functionality to create a menu: I'd like to point you to this link.
It's Android standard how to create a popup menu (which looks exactly like a dropdown list under a button).
Post a Comment for "Show And Hide Drop Down List On Button Click?"