Closed kenny0202 closed 9 years ago
Hi kenny0202,
Excellent! This is a kind of an issue.
The problem here is that hide() method checks whether the action button is shown before hiding it by calling the inherited isShown() method of the android.view.View class. However, calling this isShown() method from the onCreate() method returns false even if your button is shown (this is how actually isShown method of the View class works). That is why hide() method does not actually do what you want in the onCreate() method.
As a temporary solution you have two options:
Call setVisibility(View.INVISIBLE) for your saveButton in the onCreate() method:
ActionButton editButton = (ActionButton) findViewById(R.id.edit_button);
ActionButton saveButton = (ActionButton) findViewById(R.id.save_button);
editButton.show();
saveButton.setVisibility(View.INVISIBLE);
Leave the instantiation of the action buttons in the onCreate() method, but call hide() method for your saveButton in the onStart() method:
private ActionButton editButton;
private ActionButton saveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editButton = (ActionButton) findViewById(R.id.edit_button);
saveButton = (ActionButton) findViewById(R.id.save_button);
editButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editButton.hide();
saveButton.show();
}
});
}
@Override
protected void onStart() {
super.onStart();
saveButton.hide();
}
I would suggest you to use the second one.
I will fix this issue in version 1.0.4 today-tomorrow and you can simply move this part of the code into onCreate() method.
So, check for updates soon Have a nice day :)
sweet thank you. Excellent work on the library by the way.
Thank you!
BTW, I forgot the 3rd option you can also use:
If you just need to hide this button at the start of your activity and then to control its visibility at runtime, you can just set the visibility=invisible for your saveButton in the XML layout resource:
android:visibility="invisible"
ahh yes. I just noticed that seems like overriding the onStart method does not work.
Hi,
Issue was fixed in version 1.0.4
Please check
I have a edit and save button. When editButton is clicked the editButton hides and the saveButton shows. The problem I am having is when the activity is first loaded saveButton.hide() does not hide the button. I made a if statement to switch between the buttons but they dont work the way i want it to. I have began to make the code more redundant and nothing still works. It seems to me that my logic is correct, but the application is not doing what I want it to do.
editButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editButton.hide(); saveButton.show(); if(saveButton.isHidden()) { saveButton.show(); } } });