Test  code should use Instrumentation, which allows you to inject your code
into the application and control it through the methods there.

On Fri, Jul 3, 2009 at 12:59 PM, Mathieu Plourde <[email protected]>wrote:

>
> For the listview part, I found it. I used performItemClick.
>
> But for generating keystrokes, nothing seems to work. I tried using
> onKeyDown and onKeyUp, but it just doesn't do anything (and I need to
> generate the key strokes from the application).
>
> The only thing that seemed to have a result is
> activity.dispatchKeyEvent. But that seems to only work within the
> focused view. Like if the view with the focus is a listview, it will
> jump from listitem to listitem upon generating the Key UP and Key DOWN
> events. However, if I want to jump from an edittext to another
> edittext, it will do nothing. As if it stays within the focused
> view...
>
> Anyone knows the correct way to do this? Or a workaround?
>
> Thanks.
>
> (I'm making something for test automation purposes that is recording
> and copying what a user is doing on the emulator. Like if a use
> presses "DOWN" on his keyboard, the focus will jump from a widget to
> another. Sadly, I can't find anything that does the same thing
> programmatically.)
>
>
> On Jul 2, 5:22 pm, Mark Murphy <[email protected]> wrote:
> > Mathieu Plourde wrote:
> > > 1. How do you programmatically generate key strokes? I found some
> > > tutorials where it says to use IWindowManager, but that doesn't exist
> > > anymore in 1.5. (And WindowManager doesn't provide any function to
> > > generate key strokes)
> >
> > For your own activity, you could try manually calling onKeyDown() and
> > onKeyUp(), though I have not tried this.
> >
> > To try to control other applications, you cannot generate keystrokes,
> > AFAIK, probably for security reasons.
> >
> > > 2. How do you programmatically select one item from a ListView? Is it
> > > possible to do it with the index of the list item (it's position in
> > > the list)
> >
> > If by "select" you mean "have it appear with the orange selection
> > highlight", call setSelection() on the ListView. However, this will only
> > work if the activity is not in touch mode -- in touch mode, there is no
> > orange selection highlight except briefly when list items are clicked.
> >
> > --
> > Mark Murphy (a Commons Guy)http://commonsware.com|
> http://twitter.com/commonsguy
> >
> > Android Development Wiki:http://wiki.andmob.org
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to