android 程序 新手求指导 setOnClickListener需要在方法里面调用,比如可以放在onCreate()方法中。另外,你的第二个setOnClickListener的C应该大写的,写成小写了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package m.usewidget;import m.usewidget.R;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.view.Menu;public class MainActivity extends Activity {private TextView show;private Button press;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);show=(TextView)findViewById(R.id.show_TextView);press=(Button)findViewById(R.id.Click_Button);press.setOnClickListener(new View.OnClickListener(){public void onclick(View v){show.setText("button 被点击了");}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}重新帮你整理了下,你的事件与初始化应该放在onCreate里面 三本经典高清Android开发书籍分享 - 不需要积分(不收藏会后悔) 自己实现铃声播放和音乐播放冲突怎么办? 编译器上面的问题 Ubuntu 10.04 LTS 安装 sun-java6-jdk Android表格布局问题求解.. execSQL和insert,用哪个好点? android蓝牙开发 连接失败时如何判断是何种原因导致的失败? 怎么更新ListView?? OpenCV4Android-FaceRecognition-例程中出现的错误 安卓开发求大腿 android:fontFamily 属性的使用 使用Git上传Android代码
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.Menu;
public class MainActivity extends Activity {
private TextView show;
private Button press;protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);show=(TextView)findViewById(R.id.show_TextView);
press=(Button)findViewById(R.id.Click_Button);
press.setOnClickListener(new View.OnClickListener(){
public void onclick(View v){
show.setText("button 被点击了");
}
});
}@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;}}重新帮你整理了下,你的事件与初始化应该放在onCreate里面