WEB开发网
开发学院手机开发Android 开发 Android 中实现 Activity 的跳转 阅读

Android 中实现 Activity 的跳转

 2010-03-25 17:04:00 来源:WEB开发网   
核心提示:# <uses-sdk android:minSdkVersion="3" /> # </manifest> 然后在layout中的main加入一个id为leah1的按钮,另外再创建一个任意的layout(将要跳转到得layout),我取名为 leah1,Android

#   <uses-sdk android:minSdkVersion="3" /> 
# </manifest> 

然后在layout中的main加入一个id为leah1的按钮,另外再创建一个任意的layout(将要跳转到得layout),我取名为 leah1。

接下来是两个类,一个是AndroidForward,另一个是将要跳转到得ForwardTarget,代码分别如下:

AndroidForw:

Java代码

package com.ray.forward;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class androidForward extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button btn1 =(Button)findViewById(R.id.leah1);

btn1.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(View v) {

Intent intent = new Intent();

intent.setClass(androidForward.this, ForwardTarget.class);

startActivity(intent);

finish();//停止当前的Activity,如果不写,则按返回键会跳转回原来的Activity

}

});

}

}

package com.ray.forward;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class androidForward extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button btn1 =(Button)findViewById(R.id.leah1);

btn1.setOnClickListener(new View.OnClickListener(){

Tags:Android 实现 Activity

编辑录入:coldstar [复制链接] [打 印]
赞助商链接