getView设置为下面这样,但是运行后丢失第一项,而且只能向上滑动,而且无法显示新的Item
请问这是为什么?
@Override
public View getView(int position, View convertView, ViewGroup parent){
MyListener myListener = new MyListener(position);
if (convertView == null){
convertView = mInflater.inflate(R.layout.order_list_item, null);
int iHeight = lvRight.getHeight();
int iWidth = lvRight.getWidth();
GridView.LayoutParams params = new GridView.LayoutParams(iWidth / 3,
iHeight /3);
convertView.setLayoutParams(params);
holder = new Holder();
holder.foodAmountAdd = (Button)convertView.findViewById(R.id.food_amount_add) ;
holder.fooodPhoto = (ImageView)convertView.findViewById(R.id.food_photo);
holder.maleDescribe = (TextView)convertView.findViewById(R.id.food_describe);
holder.maleDescribe.getBackground().setAlpha(204);
convertView.setTag(holder);
}else {
holder = (Holder) convertView.getTag();
}
holder.foodAmountAdd.setOnClickListener(myListener);
return convertView;
}
你的myLitener是什么? 自定义的点击事件呀?
int iHeight = lvRight.getHeight();
int iWidth = lvRight.getWidth();
这两行代码 你确定能拿到 宽高???
获取宽高得需要WindowManager对象
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
int iWidth = wm.getDefaultDisplay().getWidth();
int iHeight =wm.getDefaultDisplay().getHeight();