如何显示随机活动时,点击按钮 [英] How can I display random activity when click button

查看:237
本文介绍了如何显示随机活动时,点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的主要活动code

I used following code in main activity

public void button(View v){

         //Create an intent to start the new activity.
            // Our intention is to start secondActivity
         Intent intent = new Intent();
         intent.setClass(this,Activity.class);
         startActivity(intent);
        }

如何显示随机活动时,点击按钮?请帮帮我!

How can I display random activity when click button? Please help me!

推荐答案

调试一些codeS上面,因为有一个在setClass()的错误。这一件作品:

debugged some codes above because there's an error in setClass().. this one works:

Random rnd = new Random();
int x=rnd.nextInt(3)+1;
Intent myIntent = new Intent();
switch(x){
case 1:
myIntent.setClass(view.getContext(),Scrn1.class);
break;
case 2:
myIntent.setClass(view.getContext(), Scrn2.class);
break;
case 3:
myIntent.setClass(view.getContext(), Scrn1.class);
break;
}
startActivity(myIntent);  

这篇关于如何显示随机活动时,点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆