我创建了自己的扩展 BaseAdapter 的适配器,并将其用于 GridView。我想获取元素的数量并将其放入 TextView。我在我的适配器中做到了:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if(convertView == null){
gridView = new View(context);
gridView = inflater.inflate(R.layout.grid_element, null);
ImageView logo = (ImageView) gridView.findViewById(R.id.grid_logo);
TextView tv = (TextView) gridView.findViewById(R.id.grid_textView1);
tv.setText(level+position);
}
else
gridView = convertView;
return gridView;
}
直到我在启动时获得不在屏幕中的元素,这似乎很好:
位置就像重置了一样。我怎样才能正确地做到这一点?