不兼容的Java方法

时间:2014-05-14 03:25:49

标签: java android

我正在尝试通过辅助教程学习Java并输入了我认为正确的代码:

package com.aide.trainer.myapp;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Set main.xml as user interface layout
        setContentView(R.layout.main);

        final TextView textView = (TextView) findViewById(R.id.mainTextView1);
        Button button = (Button) findViewById(R.id.mainButton1);

        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View p1)
            {
                // TODO: Implement this method
                TextView textView = (TextView) findViewById(R.id.mainTextView1);
                textView.setText("Clicked");
            }
        });
        button.setOnLongClickListener(new OnLongClickListener() 
        {
            @Override
            public void onLongClick(View p1)
            {

            }
        });
    }
}

但是在public void onLongClick(View p1)void附近有一个错误:

  

此方法的类型与重写方法'android.view.View.OnLongClickListener.onLongClick(android.view.View)'

的类型不兼容

我无法弄清楚我做错了什么。有谁知道吗?

1 个答案:

答案 0 :(得分:5)

OnLongClickListener中,onLongClick(…)必须返回boolean,而不是void