zoukankan      html  css  js  c++  java
  • [转]Android开发中插入新的Activity

    http://www.netvivs.com/how-to-create-a-new-activity-in-eclipse/

    Learn how to create a new Activity in Eclipse. You can just click on the New Class to create a new activity, but there is another way to do that.

    1. Go to AndroidManifest.xml in the package explorer.
    2. Click on the Application tab in the editor
    3. Click on “Add..” under the “Application Nodes” heading
    4. Choose Activity from the list in the dialog that pops up (if you have the option, you want to create a new top-level element)
    5. Click on the “Name*” link under the “Attributes for” header (bottom right of the window) to create a class for the new activity.

    Don’t forget to click on Name* so a new dialog with the new activity information is entered. Then your new class will be created.

    下文转自:http://www.pocketdigi.com/20100731/8.html

    一个Activity就相当于程序的一页,如果想要跳转到新的一页,就必须插入新的Activity。
    插入新的Activity有三步骤:
    1、建立新的Activity程序代码,这里以”new.class”为例
    2、在AndroidManifest.xml中添加新Activity的描述
    3、在原有Activity中调用启动新的Activity
    下面一步一步来,首先建立新的Activity程序代码:
    在Eclipse左侧的Package Explorer中的src下的package上点右键,New一个Class。有一点要注意,在弹出的对话框中,Superclass要选择Activity,Name必须大写(这是JAVA的规定,必须这样,否则无法建立)

    ,在新建的Name.class里插入代码:

    1
    2
    3
    4
    5
    6
    7
    8
    
    public class Name extends Activity {
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.newviewxml);
    	}
    }

    然后建立相应的描述UI的xml文件,

    右键点击 project/res/layout ,在layout 下 new->Android xml file 

    格式复制原有main.xml的格式即可,根据上面的代码(R.layout.newviewxml),这个xml文件名应该为newviewxml.xml。
    接下来第二步,在AndroidManifest.xml中添加新Activity的描述
    打开AndroidManifest.xml,切换到Application页面,在Application Nodes里,列出了这个程序目前所有的Activity(当然不包括我们现在要添加的),点右边的Add,如图:

    点击OK,打开AndroidManifest.xml,加入

    1
    
    <activity android:name="Name"></activity>

    然后是在原有Activity中调用启动新的Activity

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    Intent intent=new Intent();
    intent.setClass(Test.this,Name.class);//当前的Activity为Test,目标Activity为Name
    //从下面这行开始是将数据传给新的Activity,如果不传数据,只是简单的跳转,这几行代码请注释掉
    Bundle bundle=new Bundle();
    bundle.putString("key1","value1");//key1为名,value1为值
    bundle.putString("key2","value2");
    intent.putExtras(bundle);
    //传数据结束
    startActivity(intent);

    到这里,新的Activity就被制调用了,如果刚才在原Activity中传送了数据,用下面的代码可以在新的Activity中获取到。

    1
    2
    3
    
    Bundle bundle=this.getIntent().getExtras();
    String s1=bundle.getString("key1");
    String s2=bundle.getString("key2");
  • 相关阅读:
    Does Spring Framework support Reactive @Transaction?
    How to explain the 'WebFlux' by analogy with 'Sports' ?
    Atom 插件推荐
    PC端页面适应不同的分辨率的方法 (转载)
    JS
    JS
    apicloud
    PHP
    CSS
    屏幕适配
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2057157.html
Copyright © 2011-2022 走看看