TQC+ 107
- package com.tqc.gdd01;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class GDD01 extends Activity
- {
- private static final String TAG = "Android_Log";
- private TextView tv;
- private Button b1;
- private Button b2;
- @Override
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Log.i(TAG, "onCreate");
- tv=(TextView) findViewById(R.id.text1);;
- b1 = (Button) findViewById(R.id.button1);
- b2 = (Button) findViewById(R.id.button2);
- b1.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v){
- Intent it = new Intent();
- it.setClass(GDD01.this,GDD01_2.class);
- GDD01.this.startActivityForResult(it,0);
- }
- });
- b2.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v){
- GDD01.this.finish();
- }
- });
- }
- @Override
- public void onActivityResult (int requestCode, int resultCode, Intent data)
- {
- tv.setText(""+resultCode);
- }
- @Override
- public void onStart(){
- super.onStart();
- Log.i(TAG, "onStart");
- }
- @Override
- public void onResume(){
- super.onResume();
- Log.i(TAG, "onResume");
- }
- @Override
- public void onPause(){
- super.onPause();
- Log.i(TAG,"onPause");
- }
- @Override
- public void onStop(){
- super.onStop();
- Log.i(TAG,"onStop");
- }
- @Override
- public void onRestart(){
- super.onRestart();
- Log.i(TAG,"onRestart");
- }
- @Override
- public void onDestroy(){
- super.onDestroy();
- Log.i(TAG,"onDestory");
- }
- }
複製代碼- package com.tqc.gdd01;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import com.tqc.gdd01.R;
- public class GDD01_2 extends Activity {
- Button btn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- this.setContentView(R.layout.mylayout);
- btn = (Button) this.findViewById(R.id.button2);
- btn.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- GDD01_2.this.setResult(99, GDD01_2.this.getIntent());
- GDD01_2.this.finish();
- }
- });
- }
- }
複製代碼 |