Android 中实现 Activity 的跳转
2010-03-25 17:04:00 来源:WEB开发网# <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(){
更多精彩
赞助商链接