自定义gridview
static class ViewHolder
{
public ImageView image;
public TextView title;
public TextView time;
}
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class GridItemAdapter extends BaseAdapter
{
private LayoutInflater inflater;
private ListgridItemList;
public GridItemAdapter(String[] titles, int[] images,String[] description, Context context)
{
super();
gridItemList = new ArrayList();
inflater = LayoutInflater.from(context);
for (int i = 0; i < images.length; i++)
{
GridItem picture = new GridItem(titles[i], images[i],description[i]);
gridItemList.add(picture);
}
}
@Override
public int getCount( )
{
if (null != gridItemList)
{
return gridItemList.size();
}
else
{
return 0;
}
}
@Override
public Object getItem( int position )
{
return gridItemList.get(position);
}
@Override
public long getItemId( int position )
{
return position;
}
@Override
public View getView( int position, View convertView, ViewGroup parent )
{
ViewHolder viewHolder;
if (convertView == null)
{
convertView = inflater.inflate(R.layout.grid_item, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
viewHolder.image = (ImageView) convertView.findViewById(R.id.image);
viewHolder.time = (TextView) convertView.findViewById(R.id.description);
convertView.setTag(viewHolder);
} else
{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.title.setText(gridItemList.get(position).getTitle());
viewHolder.time.setText(gridItemList.get(position).getTime());
viewHolder.image.setImageResource(gridItemList.get(position).getImageId());
return convertView;
}
然后调用
gridView = (GridView) findViewById(R.id.gridview);
GridItemAdapter adapter = new GridItemAdapter(titles, images,description,this);
gridView.setAdapter(adapter);
自定义Gridview的适配器adapter,你可以搜一下,这个不是三言两语说得清的,基本的思想就是定义一个基本的xml布局,然后用自定义的adapter去加载显示出来就好了。
继承BaseAdapter后在layout文件中可以随意编写布局和控件,你还是多找找资料看看吧,这网上一大把,就不给你复制了。随便给你找个http://blog.csdn.net/leichelle/article/details/7951290
view嵌套,把imageview,textview,button放在一个布局view里面,再把这个view作为子view放入gridview
这就要设计GridView 的Item了,将Item设计成一个图片、文字、按钮的布局就行了