TQC-107 偵錯、呼叫activity

  • 1797
  • 0

TQC-107 偵錯、呼叫activity

這是TQC的107題,

程式碼為自行撰寫,

僅供參考。

 

主要練習偵錯、呼叫activity,

注意「AndroidManifest.xml」設定。

 

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);

    findview();
    lister();
  }
  
  public void findview()
  {
	  tv=(TextView) findViewById(R.id.text1);;
	    b1 = (Button) findViewById(R.id.button1);
	    b2 = (Button) findViewById(R.id.button2);
  }
  
  public void lister()
  {
	  b1.setOnClickListener(new Button.OnClickListener(){
	      public void onClick(View v){
	    	  Log.i(TAG, "button1 onClick");
	    	  
	    	        
	            
	            
	    	  Intent intent=new Intent();
	    	  intent.setClass(GDD01.this, GDD012.class);

	    	  startActivity(intent);
	      }	      
	    });
	    
	    b2.setOnClickListener(new Button.OnClickListener(){
	      public void onClick(View v){
	    	  Log.i(TAG, "button2 onClick");
	    	  GDD01.this.finish();   
	      }
	    });
  }
  
  
  @Override
  public void onStart(){
	  Log.i(TAG, "onStart");
    super.onStart();
    
  }
  @Override
  public void onResume(){
	  Log.i(TAG, "onResume");
    super.onResume();
    
  }
  @Override
  public void onPause(){
	  Log.i(TAG, "onPause");
    super.onPause();

  }
  @Override
  public void onStop(){
	  Log.i(TAG, "onStop");
    super.onStop();

  }
  @Override
  public void onRestart(){
	  Log.i(TAG, "onRestart");
    super.onRestart();

  }
  @Override
  public void onDestroy(){
	  Log.i(TAG ,"onDestroy");
    super.onDestroy();

  }
}

 

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);

    findview();
    lister();
  }
  
  public void findview()
  {
	  tv=(TextView) findViewById(R.id.text1);;
	    b1 = (Button) findViewById(R.id.button1);
	    b2 = (Button) findViewById(R.id.button2);
  }
  
  public void lister()
  {
	  b1.setOnClickListener(new Button.OnClickListener(){
	      public void onClick(View v){
	    	  Log.i(TAG, "button1 onClick");
	    	  
	    	        
	            
	            
	    	  Intent intent=new Intent();
	    	  intent.setClass(GDD01.this, GDD012.class);

	    	  startActivity(intent);
	      }	      
	    });
	    
	    b2.setOnClickListener(new Button.OnClickListener(){
	      public void onClick(View v){
	    	  Log.i(TAG, "button2 onClick");
	    	  GDD01.this.finish();   
	      }
	    });
  }
  
  
  @Override
  public void onStart(){
	  Log.i(TAG, "onStart");
    super.onStart();
    
  }
  @Override
  public void onResume(){
	  Log.i(TAG, "onResume");
    super.onResume();
    
  }
  @Override
  public void onPause(){
	  Log.i(TAG, "onPause");
    super.onPause();

  }
  @Override
  public void onStop(){
	  Log.i(TAG, "onStop");
    super.onStop();

  }
  @Override
  public void onRestart(){
	  Log.i(TAG, "onRestart");
    super.onRestart();

  }
  @Override
  public void onDestroy(){
	  Log.i(TAG ,"onDestroy");
    super.onDestroy();

  }
}

 

 

自我LV~