Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(MainActivity.this, Activity2.class);
startActivity(intent);
MainActivity.this.finish();
}
});
------------------------------------------------------------------------------------------
package com.example.activitytest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
/* new珨跺Intent勤砓ㄛ甜硌隅猁雄腔class */
Intent intent = new Intent();
intent.setClass(MainActivity.this, Activity2.class);
/* 覃蚚珨跺陔腔Activity */
startActivity(intent);
/* 壽敕埻掛腔Activity */
MainActivity.this.finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
沒有留言:
張貼留言