Добрый вечер,возникла вот такая проблема несовместимости типа с context.
public class FragmentMems extends Fragment {
private GridView gridView;
private GridViewAdapter gridViewAdap;
String[] items = {
"http://topmemas.top/img/img/1517414160.jpg",
"http://topmemas.top/img/img/1518633309.jpg",
"http://topmemas.top/img/img/1517859960.jpg",
"http://topmemas.top/img/img/1517640360.jpg",
"https://cdn.pastemagazine.com/www/system/images/photo_albums/memeish-top-gun/large/top-gun-meme-10.jpg?1384968217",
"http://topmemas.top/img/img/1518633309.jpg",
"http://topmemas.top/img/img/1518633309.jpg",
"http://topmemas.top/img/img/1518633309.jpg",
};
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_user_mems, container, false);
gridView = (GridView) rootView.findViewById(R.id.gridview);
gridViewAdap = new GridViewAdapter(FragmentMems.this, items);
gridView.setAdapter(gridViewAdap);
return rootView;
}
Error:(41, 56) error: incompatible types: FragmentMems cannot be converted to Context
}
public class GridViewAdapter extends BaseAdapter {
private Context context;
private String[] items;
public GridViewAdapter(Context context, String[] items){
super();
this.context=context;
this.items=items;
}
@Override
public int getCount() {
return items.length;
}
@Override
public Object getItem(int position) {
return items[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertview, ViewGroup parent) {
ImageView img;
if (convertview == null){
img = new ImageView(context);
convertview = img;
img.setPadding(5,5,5,5);
}else {
img =(ImageView)convertview;
}
Picasso.with(context).load(items[position]).placeholder(R.drawable.image)
.resize(100,100)
.into(img);
return convertview; } }