Type new AdapterView.OnItemClickListener () {} should implement the inherited abstract method AdapterView.OnItemClickListener)

The type new AdapterView.OnItemClickListener () {} should implement the inherited abstract method AdapterView.OnItemClickListener.onItemClick (AdapterView, View, int, long)

Why do I get this message when I try to create a tutorial

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();
         }
        }
        );
    } 
}
+3
source share
2 answers

Change this:

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

:

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

When overriding a super method, you need to make sure that all data types match the original types.

+6
source

Change Longto Longin onItemClick()and see if that helps.

+3
source

Source: https://habr.com/ru/post/1752472/


All Articles