如何在高炮Android的多种活动切换 [英] How to switch beteen Multiple Activities in Android

查看:158
本文介绍了如何在高炮Android的多种活动切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有8 Screenns.I有prepared 8活动的。 在第一项活动我已经给这个code 从IST活动切换到IIND 在图像按钮提供有关单击

I am Having 8 Screenns.I have prepared 8 Activities for that. In First Activity I have given this code To Switch from Ist Activity to IInd On Image Button gives On Click

public void onClick(View v) { 
Intent myIntent = new Intent(v.getContext(), Activity2.class);
     v.getContext().startActivity(myIntent);
});

怎样做才能在2日的活动切换到第3活动, 3日活动至4日的活动,等等。

What to do to Switch on 2nd Activity to 3rd Activity , 3rd Activity to 4th Activity , and so on.

请帮我在考虑。

推荐答案

下面是1,你可以做以下的方式。在这个例子中,你把屏幕上的3个按键。这是我定义的按钮,并奠定了在我的XML文件中。点击任何的3个不同的按钮,它带你到相应的活动。

Here's 1 way you could do it below. In this example, you'd put 3 buttons on the screen. These are buttons I defined and laid out in my XML file. Click on any of the 3 different buttons, and it takes you to the corresponding activity.

    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

      // Here is code to go grab and layout the Buttons, they're named b1, b2, etc. and identified as such.     
    Button b1 =(Button)findViewById(R.id.b1);
    Button b2 =(Button)findViewById(R.id.b2);
    Button b3 =(Button)findViewById(R.id.b3);

// Setup the listeners for the buttons, and the button handler      
    b1.setOnClickListener(buttonhandler);
    b2.setOnClickListener(buttonhandler);   
    b3.setOnClickListener(buttonhandler);
}           
    View.OnClickListener buttonhandler=new View.OnClickListener() { 

   // Now I need to determine which button was clicked, and which intent or activity to launch.         
      public void onClick(View v) {
   switch(v.getId()) { 

 // Now, which button did they press, and take me to that class/activity

       case R.id.b1:    //<<---- notice end line with colon, not a semicolon
          Intent myIntent1 = new Intent(yourAppNamehere.this, theNextActivtyIwant.class);
    YourAppNameHere.this.startActivity(myIntent1);
      break;

       case R.id.b2:    //<<---- notice end line with colon, not a semicolon
          Intent myIntent2 = new Intent(yourMainAppNamehere.this, AnotherActivtyIwant.class);
    YourAppNameHere.this.startActivity(myIntent2);
      break;  

       case R.id.b3:  
                Intent myIntent3 = new Intent(yourMainAppNamehere.this, a3rdActivtyIwant.class);
    YourAppNameHere.this.startActivity(myIntent3);
      break;   

       } 
    } 
};
   }

基本上我们正在做的几件事情来进行​​设置。确定按钮,并从XML布局拉他们进来。看到每个人都有分配给它的ID名称。 r.id.b1通过例子是我的第一个按钮。

Basically we're doing several things to set it up. Identify the buttons and pull them in from the XML layout. See how each has an id name assigned to it. r.id.b1 by example is my first button.

然后,我们成立了一个处理程序,侦听我的按钮点击。接下来,需要知道哪个按钮被按下。开关/箱就像是一个如果当时。如果preSS按钮B1时,code把我们带到了我们分配给该按钮的点击。在B1 preSS(按钮1),我们去了故意或活动,我们已经分配给它。

Then we set up a handler, which listens for clicks on my buttons. Next, need to know which button was pushed. The switch / case is like an "if then". If they press button b1, the code takes us to what we assigned to that button click. Press on b1 (Button 1), and we go to that "intent" or activity we've assigned to it.

希望这有助于一点不要忘记投票了答案,如果它有什么用途。我刚开始对这个东西我自己。

Hope this helps a little Don't forget to vote up the answer if it's of any use. I'm just getting started on this stuff myself.

谢谢

这篇关于如何在高炮Android的多种活动切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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