Android gridview 适配器多次调用getView()
位置为零。下面你可以看到我的 xml 代码和日志。任何人都可以告诉我这段代码中有什么错误吗?
<GridView
android:id="@+id/reward_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="@color/transparent"
android:horizontalSpacing="@dimen/reward_negative_space_medium"
android:listSelector="@color/Transparent"
android:numColumns="2"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="@dimen/reward_negative_space_medium" >
</GridView>
我的适配器代码是@Override public View getView(int position, View convertVieww, ViewGroup parent) {
if(ShopBitesLog.IS_DEBUG_ENABLED)
Log.d(Tag, "Getview calling for position : "+ position);
if (convertView == null) {
holder = new ViewHolder();
final View convertView = inflator.inflate(R.layout.reward_grid_items, null);
holder.rewardGriditemTopImg = (ImageView)convertView
.findViewById(R.id.reward_grid_top_Img);
holder.rewardGriditemBites = (TextView)convertView
.findViewById(R.id.reward_grid_pointsTxt);
holder.reward_manin_linear = (RelativeLayout)convertView
.findViewById(R.id.reward_manin_linear);
holder.relative_reward_image = (RelativeLayout)convertView.findViewById(R.id.relative_reward_image);
holder.rewardText = (TextView)convertView.findViewById(R.id.rewardText);
holder.reward_first_relative=(RelativeLayout)convertView.findViewById(R.id.reward_first_relative);
holder.reward_second_relative=(RelativeLayout)convertView.findViewById(R.id.reward_second_relative);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
if (rewardList.get(position).isAnnouncement()) {
holder.reward_second_relative.setVisibility(View.VISIBLE);
holder.reward_first_relative.setVisibility(View.GONE);
// holder.rewardGriditemTopImg.setImageResource(R.drawable.charity);
// holder.rewardText.setVisibility(View.VISIBLE);
holder.rewardText.setText(rewardList.get(position).getRewardText());
// holder.relative_reward_image.setVisibility(View.INVISIBLE);
} else {
holder.reward_first_relative.setVisibility(View.VISIBLE);
holder.reward_second_relative.setVisibility(View.GONE);
// holder.relative_reward_image.setVisibility(View.VISIBLE);
// holder.rewardText.setVisibility(View.INVISIBLE);
holder.rewardGriditemBites.setText(rewardList.get(position).getShop_bites() + " "
+ "bites");
imageBitmapLoader.DisplayImage(rewardList.get(position).getReward_image(), 0,
holder.rewardGriditemTopImg, true);
}
return convertView;
}
我的日志在这里。
03-01 11:06:06.349:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.381:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.503:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.519:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.519:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.540:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.560:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.560:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.580:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.590:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.720:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.730:D/RewardGridAdapter(827):Getview 调用位置:0 03-01 11:06:06.730:D/RewardGridAdapter(827):Getview 调用位置:0