Losing focus at buttons in android application - android

I made one simple android application and I notice next problem:
I have several controls with attached click (or i say touch) event (buttons, imageviews). Some of them are loaded from android xml file, and some I make "in fly".
Now when I scroll screen, I must 2 time click on button to make effect (click event). It seems to me that this have some connection with losing focus.
Am I right and how to solve it? I want just one click to execute some operation.
This happen only on real device (HTC Wildfire). In emulator there is no this problem.
Thanks!

Do you, by any chance, have
android:focusableInTouchMode="true"
for the Button? Because this will cause the button to need one touch to gain focus and another one to fire the click.

Related

Toggle Button yellow light/dash

I made an App with several Toggle Buttons among other constrols. In certain circumstances some of those Toggle Buttons are set checked and unchecked not phisically by the user, but programmatically.
The tests in the Android Virtual Machine shows a normal behaviour of these controls, when I check and uncheck the Toggle Buttons both phisically and programmatically.
But my surprise comes when I run the App in a real Android machine:
When unchecking any Toggle Button programmatically (no matter if I use the setChecked(false) or the toggle() functions), the Toggle Button indeed goes to the OFF state but with a yellow light/dash instead of an empty gray dash as it would be normal to infer... (Of course, when unchecking the button phisically, the problem doesn't exist)
No matter if I use:
toggleb.setChecked(false);
or...
toggleb.toggle();
Approximated Image:
I suspect that it is related to the Android version of the real device that is more advanced than the Android Virual Machine...
So, I would like to know how to turn off any dash/light of the Toggle Button programmatically when setting it up to the OFF state.
I search all over the web for that circumstance, but, incredibly, I found no mention of it...
Thank you very much in advance...
I have to add an update:
The problem appears under specific and complex conditions and only in some Android devices, as if it were a kind of unwanted side effect. This is why this problem is so strange and does not appear in eclipse's Virtual machine (API 10: Android 2.3.3) and appears in my LG G3. I have to clarify it after several tests I made because I was not aware of it.
The App where I found the problem has a large and complex code where the ToggleButtons are not activated directly by the usual OnClick method, but by an OnTouch method whose Listener is linked to a ImageView (with a View it is the same) element that covers the whole Android device screen area.
So, this virtual element cover all buttons and controls of the App. Activating the buttons is made by registering the touch coordinantes by the OnTouch method and checking if that coordinates match the area of some of the ToggleButtons.
If the coordinates match the area of one given ToggleButton and is not checked (turned off), then that ToggleButton is checked (turned on).
On the contrary, If the coordinates match the area of one given ToggleButton and is checked (turned on), then that ToggleButton is unchecked (turned off).
With some conditions, unchecking one ToggleButton, will uncheck others. This is the point where the problem appears: when unchecking the others, the yellow dash appears only in these others.
If I put some of these other ToggleButtons over the virtual screen (or transparent ImageView element), incredibly, the problem disappear for those ones, but the onTouch fucntion does not work for direct touch for those ones, so this could not be a solution for me.
I have to report all of this.
Sorry, I still can't put code because it is very large and complex.
Thank you in advance.

Touch events happen befor an activity is displayed

In my program I have 2 activities. First one contains a keyboard for Pin and a second one which is displayed right after.
When an user enters 4 pin numbers second activity starts. But the problem is if the user clicks too many times on keyboard (more than 5 click), some touch events are propagated to next activity, while the first activity is still displayed.
This behavior is also somewhat device depended, to me it occurs on Asus Memo 10 tablet with Android 4.3, but it doesn't appear on nexus 7 with android 4.4.
Is there anyway to prevent click events being propagated to another while the first is still active?
And if that is not possible is there a way to detect when is activity is fully displayed so that I can disable click events until it is displayed.
Because I would really prefer not to have any arbitrary delay after pin input.
Thanks in advance.
onStart() method is what you're looking for to disable click events, but your aproach is not a good thing, maybe you should consider to have something like "Done" button, which user will click after he finishes his input? It can also be useful because you can write code to check pin for lenght or validate

Custom view like lock/unlock screen of android

I would like to create effects like lock/unlock screen of android. I have attached the screenshot here as well. In lock screen we have 2 buttons but in my case I am having 3 buttons and the middle button must be draggable.
The middle button can be drag to left/right.
I know I have to create custom view for this to work but I don't have any idea about how to drag button left/right with nice effect(animations) which normally any android phone have.
I need guidance on this, so can anyone suggest me how to approach for this.
Basically i wish to move/slide button left and right and based on that want to take some action.
I have tried making a lockscreen application myself and i almost made it, but here are the facts you will have to face at the end
You will not be able to disable home or menu button.
you will need user permission (not the one you get while installing the application, the menu pops up every time you press the home button unless the user decides to make your application default home screen, if that does happen you have successfully made a lock screen) if you decide to make a home screen application too.
the lock screen doesn't go very well with passwords
But if it helps, here's what i did:
You need to create a service that keeps a check on the screen being off and on.
if the screen is off, you do nothing. when the screen if ON you start the activity and wait for the user to do the thing you want the user to make him unlock the screen. and when he does that you finish() the activity.
While doing that you need to setup a method that can listen to check the incoming calls you can do that by extending PhoneStateListener and also disable the back button.
Good Luck and if you are able to make any further progress do let me know.
Maybe this project could help you GlowPadView. I've used it succesfully in one project. Hope it's what you're looking for.

Android - touch two buttons at same time

What is the best way to touch two buttons at the same time? I am working on an app that has buttons, like a D-pad and a jump button, to move your character around. Right now I am just using normal buttons and handling them with an OnClickListener. I am having problems when I am running and need to jump at the same time, or if I am running to the right, then want to go left without having to pick my finger up. I know this is possible because it works greats on game like Sonic CD and some others. Any help would be greatly appreciated.
OnClick fires only on release. Instead use the touch event handlers so that when they touch occurs, you get the events. However, note that not all devices have multitouch, and thus not all of them will be able to handle the double-touch case correctly. They will provide touch events, but not two of them. Also note that you may receive multiple "pointers" within a touch event, and will have to decide which is "yours" for each button if that matters.

More than one EditText - not getting focus, no soft keyboard? (Android)

The home screen of my Android application has three EditText views, meant to be used as three different search functions, each with a "Search" button.
The app works perfectly on the device (G1) when using the trackball: I can move between the EditTexts with the trackball, all the events fire as expected, I can enter text using the physical keyboard in the selected EditText, Enter correctly submits the proper search, etc.
etc.
However, I can't switch between the EditText views using touches - only by using the trackball. Touches seem to be completely ignored by the EditText. Touches do fire for the buttons, but very hard - takes a lot of tries to make a touch register.
In the simulator, clicking on any EditText does nothing - the first one always remains selected, and I never get a soft keyboard.
This is all inside a TabHost - I've read there are some problems with that configuration, but it sounds like a slightly different issue (the EditText doesn't seem to lose focus - everything works perfectly with the trackball).
Any suggestions for what I can check?
It sounds like your touch targets are too small. I would suggest adding some padding to each of your EditTexts, or using a TouchDelegate to increase the size of the touch target.
Ah, I figured it out.
I had a ListView left in my layout from when I first set up the TabHost. Since it didn't show anything on the screen, and it was at the bottom of my layout file after everything else, I didn't notice it... Just noticed it didn't belong there and erased it, and all the controls started behaving properly.
D'oh.

Categories

Resources