How can I make buttons click at random

I have a menu with x number of buttons that all go to different pages the problem is I have to start at the button at the top n go down I'm order for it work without crashing. If I click on the second or third button without going to the prior buttons I get a crash. I'm not sure if this is the emulator or is there some java code I can put that will allow me to click any button at random? Thanks.

package com.android.nameofmyappy;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;


public class Mainmenu extends Activity { 

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainmenu);

    Button Next = (Button) findViewById(R.id.bs);
    Next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Bs.class);
            startActivityForResult(myIntent, 0);

    Button Next = (Button) findViewById(R.id.pa);
    Next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), Pa.class);
            startActivityForResult(myIntent, 0);

};
});
};
});
}
}

that is a part of the code i have more buttons that have different id and lead to diff pages successfully if i start at the top button and work to the bottom but i would like to be able to click on any button at random...

Upvotes: 0

Views: 704

Answers (1)

wangyif2
wangyif2

Reputation: 2863

One way to perform UI fuzzy testing (randomly interacting with all UI element, such as buttons) is monkey runner, you can use adb:

adb shell monkey -p <your app's package name> -v 500

This will randomly press anything 500 times to test against crashes.

Upvotes: 2

Related Questions