onClickListener问题无法找到解决方案

时间:2014-02-11 02:44:55

标签: android onclicklistener

我无法找到解决问题的方法!我一直收到错误:

  

onClickListener无法解析为    型

请帮助!!这是我的代码

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity implements onClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button send = (Button) findViewById(R.id.button1);
        send.setOnClickListener(this);
    }

    @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;
    }

3 个答案:

答案 0 :(得分:0)

尝试根据您的目标添加此方法:

@Override
public void onClick(View view)
{
    //....
    //....
    Intent intent = new Intent(MainActivity.this, SecondActivity.class);
    startActivity(intent);
    finish();
}

答案 1 :(得分:0)

onClickListener应该是这样的OnClickListener

public class MainActivity extends Activity implements OnClickListener {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button send = (Button) findViewById(R.id.button1);
    send.setOnClickListener(this);
  }

  @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;
  }

  @Override
  public void onClick(View v) {

  }
} 

答案 2 :(得分:0)

创建像addOnClickListener();这样的方法 并按照以下方式开展工作:

public void addOnActionListener(){
        Button send=(Button)findViewById(R.id.button1);
        send.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
        //...
        //...