如何在android中从URL字符串的arrayList创建gridView

时间:2011-11-24 09:52:10

标签: android android-gridview

我想从一个gridView的URL字符串中以编程方式在Android中创建一个arrayList,但它出现在一列中。我需要帮助。

我的 ImageAdapter.java

 public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private Serializable mThumbIds ;
    ImageDownLoader imageDownloader;
    private String img_url;
    int item_id;
    ConnectorInterface _conn=new ConnectorImpl();

    public ImageAdapter(Context c) {
        mContext = c;
    }
    public ImageAdapter(Context c,Serializable a){
        mContext=c;
        mThumbIds= a;
    }



    public int getCount() {
        return ((ArrayList<ItemEntity> )mThumbIds).size();

    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
       return item_id;
    }

    // create a new ImageView for each items referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null ;
        for (int x=0;x<((ArrayList<ItemEntity>) mThumbIds).size();x++){
             imageView = new ImageView(mContext);
        if (convertView == null) {

            imageDownloader = new ImageDownLoader(imageView);

                imageDownloader.execute(((ArrayList<ItemEntity>) mThumbIds).get(x).getThumbnailImg());

                imageView.setLayoutParams(new GridView.LayoutParams(50,50));
               imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(2,2,2,2);
                imageView.setVisibility(View.VISIBLE);

        } else {
             imageView = (ImageView) convertView;
        }
        }

        return imageView;
    }
}

1 个答案:

答案 0 :(得分:0)

查看此link。它会对你有所帮助。 对于显示多列中的Gridview,在GridView中设置以下属性

             android:numColumns="auto_fit"