又一直顯示錯誤,不曉得哪裡出問題 |
|
luke
更新時間:2013/1/29 下午 10:14:22 |
|
package com.tour.hellosu;
import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View;
import android.widget.Button; import android.widget.TextView;
public class HelloActivity extends Activity { private Button button1; private TextView textview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello); button1=(Button) findViewById(R.id.button1); textview=(TextView) findViewById(R.id.textView2); button1.setOnClickListener(btnDolistener);-錯誤訊息(btnDolistener cannot be resolved to a variable) } private Button.OnClicklistener btnDoListener=new Button.OnClickListener -錯誤訊息(Syntax error on token(s), misplaced construct(s))
public void onClick(View v) { // TODO Auto-generated method stub textview.setText("您按到我了"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_hello, menu); return true; } }
|
|
|
|
文淵閣工作室
更新時間:2013/1/30 上午 06:31:09 |
|
private Button.OnClicklistener btnDoListener=new Button.OnClickListener -錯誤訊息(Syntax error on token(s), misplaced construct(s))
public void onClick(View v) { // TODO Auto-generated method stub textview.setText("您按到我了"); } 改為: private Button.OnClicklistener btnDoListener=new Button.OnClickListener() {
public void onClick(View v) { // TODO Auto-generated method stub textview.setText("您按到我了"); } } |
|
|
|
luke
更新時間:2013/1/30 下午 09:47:53 |
|
謝謝! |
|
|
|
|
|
|