Android 开发之 Activity 切换
2010-04-12 16:02:00 来源:WEB开发网演示从一个Activity切换到另外的一个Activity.
第一个Activity
ActivitySecond.java代码
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ActivitySecond extends Activity
{
private Button btn2;
private Button btnClose;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
btn2 = (Button) findViewById(R.id.btn_back);
btn2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(ActivitySecond.this, ActivityChange.class);
startActivity(intent);
//如果不关闭当前的会出现好多个页面
ActivitySecond.this.finish();
}
});
btnClose = (Button) findViewById(R.id.btn_close);
btnClose.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
}
ActivityChange.java代码
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ActivityChange extends Activity {
赞助商链接