两个Activity之间切换的问题。
第一个Activity
package richy.activity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class Activity_02Activity extends Activity { /** Called when the activity is first created. */ private Button myButton = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myButton = (Button)findViewById(R.id.myButton); myButton.setText("第二个Activity"); myButton.setOnClickListener(new MyButtonListener()); } class MyButtonListener implements android.view.View.OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(); intent.setClass(Activity_02Activity.this, OtherActivity.class); Activity_02Activity.this.startActivity(intent); } }}
package richy.activity;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class OtherActivity extends Activity{ private TextView myTextView = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.string.other); myTextView = (TextView)findViewById(R.id.mytextView); myTextView.setText(R.string.app_name); }}