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
Related
What to do to give a notification in android app, when user tries to click on the button which is currently disabled ? It will be enabled in future. Then it has to perform another operation.
Help me with the disabled case ...
You should try using onTouchListener. AFAIK,setEnabled(false) disables onClick, but it should leave the onTouchListener working. Just remember one thing, return false from the listener once your work is done(in order to consume the event allow other events after it to be fired)
I would overlay it with a transparent view, and add an OnClickListener to the transparent view.
At least this way you are using a pattern you are familiar with, and it will be easier when you update the app in the future.
once you disabled that button you can no longer perform or get any kind of listeners on that disabled button. So i suggest you use the following method
you will be having a specific condition to disable the button lets say that condition is "disCondition"
disCondition = true//button disabled
button onClick(){
if(disCondition){
//Show toast message
//and change the button background to disabled image
}else{
//perform the normal button click
}
}
now change the button background according to the disCondition.
I have a bar in my app with 2 buttons side by side. One button represents the page the user is currently on and the other redirects the user to another page with the same button bar. What I want is for the button that represents the page the user is currently on to look like it is pressed (i.e. the color it would be if it is pressed). I already have it set so it can't be clicked. Is there a setting or attribute or do I HAVE to create my own selector (because I don't really understand how to implement that)?
Have never tried this but
button.setPressed(true)
should work.
Edit: You can also add
button.setClickable(false)
Edit: This does work but the order is important. Use this
btn.setClickable(false);
btn.setPressed(true);
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.
I have created a button. Now I want to do:
A single click of a button will open a dialog.
Double click of a button will open a dial pad.
OnLongtouchpress of buttons I want to change the color of the button.
Now in my case, I have used a single click event. So I want to know is there any option for double click and onlongtouchpress event on the same button if so, please suggest to me. With examples, if it is possible.
Regards
Anshuman
Use button.setOnLongClickListener to handle onLongclick event
For double click event See the followig URL
http://mobile.tutsplus.com/tutorials/android/android-gesture/
You need to set specify listeners.
Button btn = (Button)findVieByID(R.id.button1);
btn.setOnClickListener(.....);
btn.setOnLongClickListener(.....);
setOnDoubleTapListener not existing for Button
how would you disable a button until a user click on the buttons prior to it. One of the buttons has there bio info which is set in preferences. So I can't have them continue until they read the directions and fill there bio.
Disable it in the layout file and only activate it in the activity (onCreate()/onResume()) when the needed info is filled in
In onClick() for the button you want to press first call setClickable(boolean) for the button you would like to activate.
Also, if you want the button to start as being unclickable you should set the clickable attribute in your xml to false as well
<Button
android:clickable="false"
Hope this answers your question!
Perhaps make a state button for this task? Or have a state object that controls the button