0

在这里,我有 17 张图像,我想使用Grid Layout但 on getview()call 方法在活动中显示这些(连续 2 张图像)。

如何设置单个活动中的图像数量限制。

public View getView(int position, View convertView, ViewGroup parent) 
{
    ViewHolder holder = null;
    RowData rowData=null;
    rowData = getItem(TabbedHorizontalPagerDemo.startWith);

    if(convertView == null) {
        convertView = mInflater.inflate(R.layout.list, null);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    }

    holder = (ViewHolder) convertView.getTag();
    ImageView imageView1 = holder.getImage();
    imageView1.setImageResource(rowData.mImgid);

    TextView textView1 = holder.getTextView();
    textView1.setText(rowData.mTitle);
    TabbedHorizontalPagerDemo.startWith++;
    return convertView;
}

/*
 * Class to get values from a single row of list view
 */
private class ViewHolder
{
    private View mRow;
    private TextView textView = null;
    private ImageView image = null;

    public ViewHolder(View row){
        mRow = row;
    }

    public ImageView getImage(){
        if(image == null)
            image = (ImageView) mRow.findViewById(R.id.imageView1);
        return image;
    }

    public TextView getTextView(){
        if(textView == null)
            textView = (TextView) mRow.findViewById(R.id.imgText);
        return textView;
    }       
}
4

2 回答 2

1

在您的编程代码的getView(int pos, View inView, ViewGroup parent)中尝试此代码。这里我从数据库中获取数据。可能会解决您的问题:

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.gridstyle, null);
this.c.moveToPosition(pos);      
String albumName = this.c.getString(this.c.getColumnIndex("albumname"));
String image = this.c.getString(this.c.getColumnIndex("image_data"));
ImageView iv = (ImageView) v.findViewById(R.id.imagestyle);
    if (image != null) {
        Uri uri = Uri.parse(image);
        iv.setImageURI(uri);
            }

TextView fname = (TextView) v.findViewById(R.id.textstyle);
fname.setText(albumName);
于 2012-09-26T12:12:19.067 回答
0

我通过在getCount()方法中返回 8 解决了我的问题。所以它给出了单个活动的 8 个图像。

public int getCount() {
    return 8;
}
于 2013-02-23T15:51:18.243 回答