Android gridview适配器为位置零调用几个getview()

时间:2013-03-01 11:30:32

标签: android android-gridview

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>

我的适配器代码是 @覆盖     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 calling for position : 0
03-01 11:06:06.381: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.503: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.519: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.519: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.540: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.560: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.560: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.580: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.590: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.720: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.730: D/RewardGridAdapter(827): Getview calling for position : 0
03-01 11:06:06.730: D/RewardGridAdapter(827): Getview calling for position : 0

1 个答案:

答案 0 :(得分:1)

您的代码很可能没有任何问题。无法保证AdapterView将调用getView()适配器的次数。你的工作就是让getView()非常快。