下面是扩展 BaseAdapter 的 ImageAdapter。它包含将图像位图设置为 ImageView 的代码和将文本设置为 TextView 的 setText 方法。但我仍然需要将 TextView 和 ImageView 都绑定到适配器的父级。每个图像和文本将出现的实际 gridView。这个怎么做?我的代码中遗漏了一些东西。
image_item 是 listView 或 gridView 中单个视图的 xml 布局设计。它包含一个 ImageView 和一个 TextView。基本上是一个 jpeg 图像,在每个图像下方是将出现的图像的标题。
     public class ImageAdapter extends BaseAdapter {
       private Context mContext;
        public ImageAdapter(Context c) {
             mContext = c;
        }
        public int getCount() {
              return count;
        }
        public Object getItem(int position) {
              return position;
        }
        public long getItemId(int position) {
              return position;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
              if (convertView == null) {
                  LayoutInflater inflater = (LayoutInflater) mContext
                          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  view = inflater.inflate(R.layout.image_item, null);
              } else {
                  view = convertView;
              }
              ImageView i = (ImageView) view.findViewById(R.id.adapterImageView);
              i.setImageBitmap(bm); // bm = bitmap object
              // bm is the bitmap returned by an intent get extras, that code not shown
              TextView t = (TextView) view.findViewById(R.id.adapterTitleView);
              t.setText("test text");
              return view;
          }
        }