ورود

View Full Version : مشکل در فرستادن عکس به GridView



meysam jahedi
دوشنبه 27 بهمن 1393, 11:02 صبح
سلام

برای نمایش عکس در گریدویو طبق آموزش یکی از دوستان در سایت :


public class imageadapter extends BaseAdapter {
private Context context;

Integer[] aksahayeItemGrid;

public imageadapter(Context context,Integer[] aksahayeItemGrid){
this.context = context;
this.aksahayeItemGrid = aksahayeItemGrid;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return aksahayeItemGrid.length;
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return aksahayeItemGrid[arg0];
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}

@Override
public View getView(int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub
view = LayoutInflater.from(context).inflate(R.layout.row_ gradview, parent,false);
ImageView item = (ImageView)view.findViewById(R.id.row_image);
item.setBackgroundResource(aksahayeItemGrid[position]);

return view;

}

}

و در اکتیویتی :


protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
grid=(GridView)findViewById(R.id.gridView1);
aksahayeItemGrid = new Integer[] {
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.h,
R.drawable.i,
R.drawable.j,
R.drawable.k,
R.drawable.l,
R.drawable.m,
R.drawable.n,
R.drawable.o,
R.drawable.f,
R.drawable.g};
grid.setAdapter( new imageadapter(this,aksahayeItemGrid ));


نمیدونم چرا تصاویر رو نشون نمیده و فقط همون یه عکسی که تو ImageView همون اول تو اکتیویتی گذاشتم تو گریدویو تکراری تو همه آیتم ها نشون داده میشه