How to click a button of android program through monkeyrunner? - android

I succeeded to install apk file on android emulator using Jython (monkeyrunner.bat). I also used this line of code to start the main activity: device.startActivity(component=runComponent) Now what i want is to press a button on the activity which i launched, if the button name is "Submit" than how can i send key events to press this button. Thanks and please give response ASAP.

You can use Up and down key events to go to a particular button and use center button to click on that button.
For example
device.press("DPAD_DOWN", MonkeyDevice.DOWN_AND_UP) or device.press("DPAD_UP", MonkeyDevice.DOWN_AND_UP)
to reach the particular button and then click that button using
device.press("DPAD_CENTER", MonkeyDevice.DOWN_AND_UP)
You can't click the button with the button name or id.

Another method to click on the button is to use the touch event of the MonkeyDevice. With this method you can specify the location of the button and then send a touch event to the display. For example lets say your button locates at bottom center of the screen. then you can send a touch event like this
device.touch(240, 450, 'DOWN_AND_UP') - (For HVGA screen)
This will click the location (240, 450). These co-ordinates are calculated from left top corner and the first value is X co-ordinate.

Related

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

How to detect multiple tapping buttons

Actually my problem is I am making custom dial pad in android I pressed one button and I want to press one more button to get the value of that button I am getting first button value only. When I remove completely finger from first button that time only I am able to press second button

Generic click event in Android

Recently I was able to create a tablet software for my Cerebral Palsy girl to "talk" to me, since she can't speak.
Well, a friend of mine has Amyothrophic Lateral Sclerosis (ALS). He can move just one finger and he is willing to use my daughter's software to be able to "talk" again.
Since he can move just a finger, I created a version where each item "blinks" (in yellow) for some time (just one second) and if he presses a mouse button, the item focused (in yellow) is activated.
See below:
It works if you leave the mouse over the black portion of the screen. If mouse is over the buttons, it won't work, it will click the button where the mouse is over.
Also, if he uses a keyboard and he presses the ENTER key, it will activate the first button, then, if he clicks the left arrow and then presses the ENTER again, it will activate the second button and so on.
So, I wish I could create an generic event that if he would press the ENTER key, just the selected (in yellow) item would be activated.
Any ideas?
Well you could make two different modes. One where there are click listeners for each picture,and another where simply a click anywhere on the screen is recognized ( ex. find the largest layout id and set a listener). Then in the second mode, use
http://developer.android.com/reference/android/view/KeyEvent.html
to detect KeyEvents such as Enter, and handle them depending on the highlighted View.

Event handling for button

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 to Add a Button on the home screen in android?

I want to add a button on the home screen and want to code in the click event of that button.
I have an application which has an activate button,As soon as this activate button is clicked i want that a Button gets created on the home screen and i want to code some database queries in its click event.I have already created that application,Now i want to place the button on the home screen.How do i do that.
Thanks in Anticipation.
I don't think you can create a button on the Home Screen on-the-fly by coding. In my book, the only way to get a button on the Home Screen is if the user adds it as a widget.
If you are using xml layout for it add the button widget you needed and set it's visibility by android:visibility="gone",when you clicked the first button to activate the button to display,make it to visible by getting the id of the corresponding button
for eg: btn2.setVisibility(View.VISIBLE);

Categories

Resources