Android:通过单个GridView适配器调用另一个GridView适配器

时间:2015-01-04 16:19:49

标签: java android gridview mobile android-adapter

首先,我在GridView上填充ArrayList。在GridView中,我需要在另一个GridView上填充更多数据。基本上从第一个适配器调用第二个适配器。

到目前为止我的代码:

    public class ProductGridInflator extends ArrayAdapter<Product>{
    ArrayList<Image> dbImages = new ArrayList<Image>();
    GridView multiplePics;
    Context ctx;
    public ProductGridInflator(Context context, int resource,ArrayList<Product> objects, ArrayList<Image> obj) {
            super(context, resource, objects);
            // TODO Auto-generated constructor stub
            this.dbProducts = objects;
            this.ctx = context;
            this.resource = resource;
            this.dbImages = obj;
        }

    @Override
        public View getView(final int position, View convertView, final ViewGroup parent) {
            // TODO Auto-generated method stub
            View child = convertView;
            final RecordHolder holder;
            LayoutInflater inflater = ((Activity) ctx).getLayoutInflater(); // inflating your xml layout

            if (child == null) {            
                child = inflater.inflate(R.layout.grid_single, parent, false);
                multiplePics = (GridView) child.findViewById(R.id.moreImagesGrid);
             }

    if(dbImages.size() > 1)
    {
        OtherImagesAdapter adapter = new OtherImagesAdapter(ctx, R.layout.grid_single, dbImages);
        multiplePics.setAdapter(adapter);
    }
  return child;
}

理论上这是对的。这似乎不起作用。代码有什么问题?

0 个答案:

没有答案