Ad
How To Add Images In Gridview? I Am Getting Grid Data From API But I Want To Add Images To That GridView
I'm using grid view in my project. I am getting data from API. But I want to add images to that grid. The below given code is adapter class code
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder mHolder = new ViewHolder();
ImageView imageView;
if (convertView == null) {
convertView = inflater.inflate(R.layout.adapter_category, null);
mHolder.tvCategoryName = (TextView) convertView.findViewById(R.id.tvCategoryName);
mHolder.tvCategoryDescription = (TextView) convertView.findViewById(R.id.tvCategoryDescription);
mHolder.ivItemImage = (ImageView) convertView.findViewById(R.id.ivItemImage);
convertView.setTag(mHolder);
} else {
mHolder = (ViewHolder) convertView.getTag();
}
mHolder.tvCategoryName.setText(getItem(position).getName());
mHolder.tvCategoryDescription.setText("");
mHolder.ivItemImage.setImageResource(mThumbIds[4]);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("THIS IS CATEGORY TYPE", mCategoryType + "");
if (mCategoryType == ConstantsInternal.categoryType.MainCategory.getValue()) {
Log.e("RENT", "MAINCATEGORY");
Bundle mBundle = new Bundle();
mBundle.putString("itemName", getItem(position).getName());
Log.e("MAINCATEGORY", getItem(position).getName());
MyActivity.getInstance().subcategory(mContext, mBundle);
}
}
});
return convertView;
}
private Integer[] mThumbIds = {
R.drawable.camera ,R.drawable.ic_cart, R.drawable.commericalvehicles, R.drawable.garments
};
My Expected result is I want images in Gridview. Each and every grid should be different image. I am new to this. Thanks in advance.
Ad
Answer
instead of mHolder.ivItemImage.setImageResource(mThumbIds[4])
.
try this
mHolder.ivItemImage.setImageResource(mThumbIds[position])
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad