0

我开发了一个应用程序,在其中显示数据Gridview。所有数据都来自本地存储。我能够正确显示每个数据并且没有问题。但是当我滚动Gridview并转到底部并返回时Top,它会改变位置。有时当我向下滚动并返回顶部时,屏幕上会出现一个空白屏幕;根本找不到数据!

所以我认为有问题getView()。我无法找出问题所在

代码getView()

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder viewholder;
    // LayoutInflater inflator = activit.getLayoutInflater();
    if(convertView == null) {
        // recycled view is null so create it.
        viewholder = new ViewHolder();
        convertView = inflator.inflate(R.layout.gridviewrow, null);
        viewholder.imgvGridicon = (ImageView) convertView.findViewById(R.id.imgvGridicon);
        viewholder.txtGridItemlabel = (TextView) convertView.findViewById(R.id.txtGridItemlabel);
        convertView.setTag(viewholder); 
    } else {
        viewholder = (ViewHolder) convertView.getTag();      
    }  
    if ((lstpinfo.get(position).appname.toString()) != null) {
        viewholder.imgvGridicon.setImageDrawable((lstpinfo.get(position).icon));
        viewholder.txtGridItemlabel.setText(lstpinfo.get(position).appname.toString());
    }
    return convertView;
}

更新:: Intitalize of inflater::

private LayoutInflater inflator;

     private ArrayList<PInfo> lstpinfo = new ArrayList<PInfo>();
     public GridViewAdapter(Context cntx, ArrayList<PInfo> lstpinfo) {

            activit = cntx;
            inflator = LayoutInflater.from(cntx);
            this.lstpinfo = lstpinfo;

        }
4

1 回答 1

0

您必须将视图高度设置为固定值。android gridview 中存在不同高度的滚动错误。请参阅此内容以供参考。

于 2012-07-13T07:28:31.377 回答