Give notification for disabled button in Android - android

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.

Related

Drag and Drop on Disabled ImageButton

When I drag and drop something onto an image button, I want it to change colour.
This works fine when the button is enabled using this code:
DragEvent.ACTION_DRAG_DROP -> {
it.background.mutate().setColorFilter(ContextCompat.getColor(mContext, R.color.entered_zone), PorterDuff.Mode.SRC_IN)
return#OnDragListener true
}
However, if I do:
endorsedBtn.isEnabled = false
Then the button will not change colour.
Why is this and is there something I can do?
From the documentation:
Note that this step only occurs if the user drops the drag shadow within the bounding box of a View whose listener is registered to receive drag events. If the user releases the drag shadow in any other situation, no ACTION_DROP drag event is sent.
Disabling your image button also disables the listeners for it.
You can create a custom button and decide on your own inner disabling function.
More information here.

Android Button Click not go through, but action still take place

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

android button listener for some combination

I m trying to build an app in which I want to use combination of buttons to give input and I want that when user presses multiple buttons then they can press buttons in a gap of 2 sec and then finally I want to write code for the combination of buttons. Is there any listener for this type of operation?
No there is no listener Nidhi. you may create a flag and set it on button click and unset in a timer. so when user click on a button he will not be able to click other button until timer unset the flag.

Android Method to Enable/Disable Touch Screen

Hi there is thery any way to invoke a method that enables or disables the Touch Screen of Android?
I want this, because I have several buttons on my activity. When the user clicks on a button, it takes a few seconds to start the following activity, and because of that, while waiting that time, I don't want the user to be able to press anything.
I used a boolean that is True at start, then It changes to false when I click on the first button. And to every click on a button I check if the boolean is true...
But the problem is that Visually the user can click the button, it gets that look of being pressed..
So is there any good method that disables the entire touch screen ? And another that enables the entire touch screen ?
Thanks alot in advance ;)
But the problem is that Visually the user can click the button, it gets that look of being pressed
Disable the buttons, using setEnabled(false). This will not only prevent the user from clicking on them, but they will visually appear disabled, to let the user know that the user cannot click on them. It is important for the user to get the proper visual feedback about the buttons being disabled (and later enabled).
is thery any way to invoke a method that enables or disables the Touch Screen of Android?
Not really.

How do I set a button as always pressed? (Android)

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);

Categories

Resources