3

new AdapterView.OnItemClickListener(){} 类型必须实现继承的抽象方法 AdapterView.OnItemClickListener.onItemClick(AdapterView, View, int, long)

为什么我在尝试构建教程时收到此消息

package Fedail.Hello.Layout;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;


public class Layout_Feras extends Activity {
    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener(){
         public void onItemClick(AdapterView<?> parent, View v, int position, Long id){
          Toast.makeText(Layout_Feras.this,"" + position, Toast.LENGTH_SHORT).show();
         }
        }
        );
    } 
}
4

2 回答 2

6

改变这个:

public void onItemClick(AdapterView<?> parent, View v, int position, Long id)

对此:

public void onItemClick(AdapterView<?> parent, View v, int position, long id)

覆盖超级方法时,您必须确保所有数据类型与原始类型匹配。

于 2010-06-30T14:27:00.597 回答
3

将您的更改Longlongin onItemClick(),看看是否有帮助。

于 2010-06-30T14:26:21.463 回答