Iam開發Android應用程序,顯示圖像&與gridview顯示的圖像&現在我做了gridview圖像顯示drawable.I從json中獲取文本值arraylist變量。gridview與動態文本視圖和可繪製圖像
代碼我用於顯示僅適用於圖像:從含有15 values.when沒有從mThumbIds(即,textvalues>圖像)圖像,那麼它應該把我的默認一個異步任務
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_front_page);
GridView grid=(GridView)findViewById(R.id.maincatgrid);
grid.setAdapter(new ImageAdapter(this));
grid.setColumnWidth(170);
grid.setVerticalSpacing(20);
grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
grid.setNumColumns(GridView.AUTO_FIT);
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c){
mContext = c;
}
public Integer[] mThumbIds = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7,
R.drawable.image8,
};
public int getCount() {
// TODO Auto-generated method stub
return mThumbIds.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return mThumbIds[position];
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View MyView = convertView;
// TODO Auto-generated method stub
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(170, 150));
imageView.setAdjustViewBounds(false);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}
}
蔭得到的TextView值圖像R.drawable.no_image.Is有任何方法來實現這個然後PLZ建議我。提前感謝。
使用通用圖像加載程序。 – Raghunandan
Thankyou.can你提供給我的鏈接? – Neeha