I am currently working on a calculator application which has a scaleable NumPad with a lot of buttons:
The Buttons on the NumPad should register user input when they are clicked. Additionally, if the user performs a zoom-gesture on the NumPad it should increase in size / decrease in size.
What's my Problem?
I want to handle onClick events if the user taps a button, but also handle a gesture if the user pinch-zooms on the buttons. How can I do that?
GitHub Repo: https://github.com/Max-We/TheCalculator
Hi #FxMx you can have a look at this - Pinch Zoom and onClickListener for same layout not working in Android
You can set a ontouchlistener on your NumPad layout and do nothing if its single touch and you can set onClick listeners to your NumPad buttons which can perform your register events.
Related
I have a ViewPager set up with a TabLayout at the top. The app is running on a device with physical d-pad directional keys that can be used to move the control focus.
How can I detect when the focus is moved to specific tabs in the TabLayout?
I can see the Tab highlight when the focus is received, but I am unable to find any events that might allow me to detect this.
Also, TabSelected doesn't work, as it doesn't fire until the center key of the d-pad is pressed to "select" the focused tab.
You can add custom view to your tab, and then setOnFocusChangeListener for this view.
I have a Floating Action Button with a custom menu of mini Floating Action Buttons, that appears upon click on the main Floating Action Button.
The mini FABs are in a LinearLayout.
I want that after opening the FAB menu, when the user clicks elsewhere, the menu disappears. However, I haven't been able to find how to do this.
What listener do I need for this?
Any help?
Thanks.
You are most likely interested in a custom FloatingActionButton.Behavior:
https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.Behavior.html
https://medium.com/#nullthemall/floatingactionmenu-floatingactionbutton-behavior-dd33cc0d9ba7#.jsvuvz2rk
Otherwise you can simply set the Visibility of the respective controls to Gone based on a OnTouchListener that checks if you are touching outside the FAB.
I am creating a panel showing many different kind of widgets such as button. The panel allows to zoom in and zoom out. It is required to show whole panel in the beginning. However, some users may touch more than one button when the panel is too small.
I want to handler the situation like chrome in Android. When the user touches more than one link, a pop up panel will be showing.
What library or APIs may I use?
Thanks!
You could place your Buttons in a FocusPanel implementing a ClickHandler to open your desired popup- thus when your user clicked between two buttons the click is registered and you can handle it.
Note, you will have to place a FlowPanel in that FocusPanel to place more than one button inside.
If you want to react on hover instead of on click, use HoverHandler instead.
I have a simple soundboard which uses Buttons to represent the sounds. When a sound button is clicked. The background image is changed using the view.
Button butt = (Button)view;
butt.setBackgroundResource(buttons_on[media]);
buttons_on is a int[] representing the drawables of the buttons.
This all works perfect, but I also use a FragmentActivity to create a paged App. The App has 4 different pages which you can swipe through. When I change a button using the above code and swipe two pages to the right and than swipe back. The image of the button has changed back to it's default defined in the page.xml.
How can I prevent this behavior?
change the Buttons to ImageButtons and setting the src?
somehow prevent the page from reloading
Instead of doing that you should look at how to use a StateListDrawable. It will simplify your approach.
I create an app which need to disable all buttons to allow user to leave the application - back button, menu button, camera button, call button, etc, and app should have 1 button for exit. I don't know how to disable all buttons. Tell me please, thank you
The Physical buttons? No, you can't disable all of them. Home button needs to work... Android - Is It possible to disable the click of home button
Related: Android: mass enable/disable buttons
Try this: when you enter the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
and when you exit the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION);