Всем привет.Возникла необходимость при нажатии на картинки,загруженные с помощью picasso,открывать на большую часть области экрана.Но setImageResource несовместим со String.
public class GridViewAdapter extends BaseAdapter {
private Context context;
public String[] items = {
"http://topmemas.top/img/img/1517414160.jpg",
"http://topmemas.top/img/img/1518633309.jpg",
"http://topmemas.top/img/img/1517859960.jpg",
};
public GridViewAdapter(Context context){
this.context=context;
}
@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(10,10,10,10);
}else {
img =(ImageView)convertview;
}
Picasso.with(context).load(items[position]).placeholder(R.drawable.image)
.resize(320,320)
.into(img);
return convertview;
}
}
public class FullImageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_image);
Intent i =getIntent();
int position=i.getExtras().getInt("id");
GridViewAdapter adapter = new GridViewAdapter(this);
ImageView img=(ImageView)findViewById(R.id.imageViewfull);
img.setImageResource(adapter.items[position]);
}
Error:(23, 43) error: incompatible types: String cannot be converted to int
public class FragmentMems extends android.support.v4.app.Fragment {
private GridView gridView;
@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);
gridView.setAdapter(new GridViewAdapter(getContext()));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent i =new Intent(getContext(),FullImageActivity.class);
i.putExtra("id",position);
startActivity(i);
}
}); return rootView;
}
}