只有通过分享源码,才能共同前进吧。
学习了半天的android,晒上我的第一个小小的android程序。OnClickListener()有点搞
package mth.android;
import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;
public class AndroidActivity extends Activity implements View.OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //final View textDisplayer = this.findViewById(R.id.displayText); //final TextView textDisplayer = (TextView) this.findViewById(R.id.displayText); Button startActivityButton = (Button)this.findViewById(R.id.startAndroidActivity); startActivityButton.setOnClickListener(this); /* Button startActivityButton = (Button)this.findViewById(R.id.startAndroidActivity);
// when class not implementing View.OnClickListener() startActivityButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) { // TODO Auto-generated method stub display(textDisplayer); } }); */ /* View startActivityButton = this.findViewById(R.id.startAndroidActivity); startActivityButton.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { // TODO Auto-generated method stub textDisplayer.setText("Hello World"); textDisplayer.setBackgroundColor(0xFFFFFFFF); } }); */ /* TextView text = new TextView(this); text.setText("Hello World"); setContentView(text); */ } public void display(TextView tv) { tv.setText("Hello world"); tv.setBackgroundColor(0xFFFFFF00); }
public void onClick(View v) { // TODO Auto-generated method stub final TextView textDisplayer = (TextView) this.findViewById(R.id.displayText); textDisplayer.setText("Hello world"); textDisplayer.setBackgroundColor(BIND_AUTO_CREATE); }}