Create a custom adapter to view the grid. And install this custom adapter to view gird. Here is the xml code for the grid element.
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<imageview android:id="@+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</imageview>
</linearlayout>
and here is the xml for the main layout.
<gridview xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
</gridview>
and here is a custom adapter class that extends from BaseAdapter
public class ImageAdapter extends BaseAdapter
{
Context context;
public ImageAdapter(Context context)
{
context = context;
}
@Override
public int getCount()
{
return 9;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if ( convertView == null )
{
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.grid_item, null);
ImageView iv = (ImageView)v.findViewById(R.id.grid_item_image);
iv.setImageResource(R.drawable.icon);
}
return v;
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
}
Hope this helps you.
source
share