3

I am creating an adapter image and I am having this 2 errors:

this is the code

public class GridViewAdapter {

    private Context mcontext;
    private int layoutResourceId;

    public GridViewAdapter(Context context, int layoutResourceId, ArrayList<Listitem> listitem) {
        super(context, layoutResourceId, listitem);
        this.layoutResourceId = layoutResourceId;
        this.mcontext =context;

    }

this is second error

cannot resolve method getitem()

   ` Listitem item = getItem(position);`

if (row == null) {
            LayoutInflater inflater = LayoutInflater.from(mcontext);
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.imageTitle = (TextView) row.findViewById(R.id.text);
            holder.imageView = (ImageView) row.findViewById(R.id.imageView);
            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }
        Listitem item = getItem(position);
Moudiz
  • 7,211
  • 22
  • 78
  • 156
  • I think @Blackbelt answer is working for you. Moreover, you can read my answer at the following for reference when needed http://stackoverflow.com/questions/33047156/how-to-create-custom-baseadapter-for-autocompletetextview/33049491#33049491 – BNK Oct 14 '15 at 12:39
  • 1
    thanks man ill check it – Moudiz Oct 14 '15 at 12:44
  • Perhaps you have forgotten my answer at one of your previous questions http://stackoverflow.com/questions/32942144/all-images-not-displaying-from-the-same-url `public class CustomGridViewAdapter extends ArrayAdapter` :) – BNK Oct 14 '15 at 14:12
  • @BNK yes thank for reminding me about your answer. i Will look at it again. – Moudiz Oct 14 '15 at 21:30

2 Answers2

6

super try to invoke the super class. You are extending nothing, so implicitly, you are inheriting from Object which, in turn, has no such constructor (a constructor that takes three parameters)

Change

public class GridViewAdapter {

with

public class GridViewAdapter extends ArrayAdapter<ListItem> {
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • if you prefer to post this as another question I will but I am having error in calling the adapter `GridViewAdapter adapter = new GridViewAdapter(this, R.layout.grid_item_layout, Listitem);` the error is on `this`. I added Mainactivity.this didnt work. I am calling the adapter in okhttp class .. what should I replace with this ? – Moudiz Oct 14 '15 at 12:43
  • the first parameter is a Context object. Ask yourself is `this` a Context ? – Blackbelt Oct 14 '15 at 12:47
  • 1
    @Moudiz Since you use okhttp in asynctask class, so instead of "this", you can use mContext = this, then use mContext in the constructor of your adapter, as in my answer link above – BNK Oct 14 '15 at 12:50
  • or if you are instantiating it in an innerclass, and the outer class is an Activity, you can use `NameActivity.this`. If the outer class is a Fragment you have to use `getActivity()` – Blackbelt Oct 14 '15 at 13:57
  • @Blackbelt can you check this please http://stackoverflow.com/questions/33197213/styling-bottom-action-icon-postion-and-background-color – Moudiz Oct 18 '15 at 11:10
2

As we know super in java is calling the extended class constructor and in your case it has no extended class. Always remember that if no class is extended super calls the no arg constructor of Object class and object class has no constructor with three parameters.

mohor chatt
  • 356
  • 1
  • 8