I have an android application where I want to display a LinearLayout when user clicks on options button(I am setting the linear layout's visibility to visible in onCreateOptionsMenu) and make it invisilble when user clicks on back button.
This works fine when I press the option button and then the back button-the view comes up and then goes away respectively.
The problem is when I press the option button again, the linearlayout does not show even though the visibility is being set to visible.
However, log tells me that the methos onCreateOptionsMenu is entered.
Why would this happen?
onCreateOptionsMenu is called only once per activity. In your case you have to code in onPrepareOptionsMenu. This will be called every time the user presses menu key.
Why do you want do this? For android users relevant reaction for menu button is option menu.
What about question, try use View.bringToFront() - it will bring view in front of all views of the same parent.
Related
I would like to create activity in which it would be explained how the app is supposed to be used. On a click on a button, I would like an Activity to be opened which has next and previous buttons on the bottom. So the first screen after the click on a button would show the first instruction and you can press next to see the next instruction which opens a new screen. After going through all the instructions, I would like a Finish button to return back to the main activity.
My question is can this be made in a single activity or is it actually more activities that differ only by the text and pictures they contain?
Yes it can be done in only one activity(actually 2 if you include the main activity).
What you can do is have multiple TextViews, and when the next button is pressed, you can toggle that 1st instruction's visibility
. And so on for the next instructions. The Next/Previous buttons should determine what Textview is currently visible, so they can keep track what Textview to show next. Use switch statement
I want when a button is pressed in my activity, for the click not to occur (such as clickEnabled being false) but I want the action that would have occurred to still happen.
For example, say I have a Dialer application:
When button "One" is pressed, the user will not see that the button was actually clicked, but the action of adding a 1 to the edittext will still occur. Thank you for your help!
I think you can make a selector as your button's background.and most important is samecolor no matter that is click , touch or idle . So through this ,you fake a no click effect.
And same time ,you can also add a click listener to this button to get the click event.
Hope that give you some suggestion.
I think you should simply use onTouchListener event for buttons instead of onclickListener
I'm doing an appication under phonegap (more specific in android). How can I disable the home, menu and back buttons in the screen, the idea is when i press any of the buttons, show a verification dialog, if the answer is correct, close the app. When i assign the function button doesn't show the dialog
For the home menu remove the onCreateOptionsMenu() function and also you wouldn't need the onOptionsItemSelected() function, so to hide the menu remove these two.
For the back buttons there are two of them:
The hard button in device that navigates in the app until it hits the main activity then pops out of the app, can be controlled by overriding this method onBackPressed()
And the one in the action bar that navigates all inside the app itself but never pops the user out of the app, can be set by setDisplayHomeAsUpEnabled() which takes a Boolean true to make it working, false to disable it.
When my activity starts the button starts as below image, seems that it is selected.
button seems to be selected http://kodeinfo.com/wp-content/uploads/2014/03/post4_1.jpg
Button seems to be selected but I don't select it neither on activity nor layout.
I had checked and this is not related to focus. I tried starting the activity with requestFocus() on a button and does not have the same behavior.
Does anyone knows what is that? What is this state for the button? I don't want this behavior in my app, but I'm not being able to understand the issue in my code because I don't know what this state is.
I created an Activity which allows navigating between pages with a couple of Buttons (Previous and Next). When the user clicks one of the buttons, the Activity (same) needs to be "refreshed". In order to do this, I set up the buttons to make a call to
onCreate(this);
after they set up the other stuff that the activity uses for the paging to work.
And it is working so far, but I'm wondering if there is a better way. Is there?
You should rethink your approach. Having Previous and Next buttons looks like an iphone's NavigationBar View. Remember that in android you have the back button, so a previous button shouldn't be necessary.
If you wish to do it, check Android's Activity Lifecycle. You should update your Activity on the onStart() method and avoid the call to onCreate(this) which doesn't sound good.
The activity displays data related to a certain day. The navigation allows choosing the day which is being displayed. As such, clicking one of the buttons changes the information which is displayed.
Example:
When the Activity first loads, it shows a given day - let's say August 23rd. Then when the user clicks the activity's "Previous" Button, the Activity shows August 22nd.
Then the user clicks the "Next" button and the Activity shows August 23rd again. If the user clicks the "Next" button again, the Activity will show August 24th.
Doesn't it seam a little strange to only have a "Next" (and rely on the physical "Back" button) ?
Thanks.
I fixed this trough refactoring:
Created a new function with the code that was being executed in onCreate (i.e. Layout initialization, database access and information display). The new function is called by the onCreate method (when the Activity gets the "Create" notification) and at anytime that I need to "refresh" the contents of the Activity (i.e. when a button is pressed).
Thanks for your comments.