I'm currently developing an android application which needs to show a book shelf where it contains maximum of 3 images in each row. I'm using gridview for that. But i'm stuck in one point where i'm not able to change the background of a whole row in gridview. can anyone tell me how to do this?
The adapter used for gridview
private class SampleGridAdapter extends BaseAdapter{
private Context context;
private int[] images = {"R.drawable.img1","R.drawable.img2","R.drawable.img3","R.drawable.img4","R.drawable.img5","R.drawable.img6","R.drawable.img7"};
public SampleGridAdapter(Context context) {
super();
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return images.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
View v = null;
ImageView coverImageView;
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.bookgrid, null);
coverImageView = (ImageView) v.findViewById(R.id.coverImageView);
coverImageView.setImageResource(images[position]);
coverImageView.setScaleType(ImageView.ScaleType.FIT_XY);
return v;
}
}
bookgrid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shelfimage" >
<ImageView
android:id="@+id/coverImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingBottom="0dp"
android:paddingLeft="25dp"
android:paddingTop="6dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
I have set the number of columns as 3 in my gridview declaration. Here i'm setting the background in xml file as android:background="@drawable/shelfimage". but it is setting that background for each item seperately...... I want to set a single image as background for each row (having 3 items)....