我制作了一个应用程序,其中我在服装gridview中显示数据并且进展顺利但问题是当我滚动它并且返回到顶部然后所有项目位置可以自动更改。并且一段时间它滚动后没有出现。我的代码是我认为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.griedviewrow, null);
viewholder.imgvGridItem = (RelativeLayout) convertView
.findViewById(R.id.rlGreidItemicon);
viewholder.txtGridItemlabel = (TextView) convertView
.findViewById(R.id.txtGridItemlabel);
if ((lstpinfo.get(position).appname.toString()) != null) {
viewholder.imgvGridItem.addView(getimageviewimage(lstpinfo
.get(position).icon));
viewholder.txtGridItemlabel
.setText(lstpinfo.get(position).appname.toString());
}
}
return convertView;
}
答案 0 :(得分:0)
看起来转换视图逻辑没有完全实现。
当你滚动时,你得到的是非null的convertView,那时你需要在那里设置新的数据,在这种情况下你什么都不做....... +你没有在标签中设置ViewHolder以从convertView取回它并使用它。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("getView " + position + " " + convertView);
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item1, null);
holder = new ViewHolder();
holder.textView = (TextView)convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.textView.setText(mData.get(position));//<========== see it .....
return convertView;
}
}