2

ViewHolder を使用して、リストビュー項目の偶数と奇数の位置に基づいて膨張させるには、2 つのレイアウトが必要です。偶数の位置では別のレイアウトが必要で、奇数の位置では同じ要素でレイアウトが異なる別のレイアウトが必要です。実装しましたが、位置に関係なく、さまざまな位置でランダムなレイアウトが得られます。それを解決するために何をする必要がありますか。ありがとう。

public SimpleAdapter(ArrayList<WishListData> wishDataList, Context context,
        ListView swipelistview) {
    super(context, android.R.layout.simple_list_item_1, wishDataList);
    notifyDataSetChanged();
    SimpleAdapter.wishListData = wishDataList;
    this.swipelistview = swipelistview;

    mPreferences = new Preferences(context);
    SCREEN_WIDTH = mPreferences.getScreenWidth();
    SCREEN_HEIGHT = mPreferences.getScreenHeight();
    mFunctions = new UserFunctions();
    this.context = context;
    imageloader1 = new ImageLoader1(context);
    userImageLoader = new UserImageLoader(context); 

}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    ViewHolder viewHolder = null;
    View row = convertView;
    if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        System.out.println("position "+ position);
        if ((position % 2) == 0) {

            row = inflater.inflate(R.layout.single_wish_view_right, parent,
                    false);

        } else if ((position % 2) == 1){
            row = inflater
                    .inflate(R.layout.single_wish_view, parent, false);

        }
        viewHolder = new ViewHolder();
        viewHolder.back = (LinearLayout) row
                .findViewById(R.id.back);
        viewHolder.lenear = (LinearLayout) row
                .findViewById(R.id.linear);

        viewHolder.front = (RelativeLayout) row
                .findViewById(R.id.front);
        viewHolder.likeButton = (ImageButton) row
                .findViewById(R.id.likemain);
        viewHolder.deathWish = (TextView) row
                .findViewById(R.id.death_wish);
        viewHolder.time = (TextView) row
                .findViewById(R.id.time_wish);
        viewHolder.name = (TextView) row.findViewById(R.id.name1);
        viewHolder.commentButton = (ImageButton) row
                .findViewById(R.id.comment);
        viewHolder.shareButton = (ImageButton) row
                .findViewById(R.id.sharemain);
        viewHolder.helpButton = (ImageButton) row
                .findViewById(R.id.help);

        viewHolder.profilePic = (ImageView) row
                .findViewById(R.id.profile_image);
        viewHolder.likecount = (TextView) row
                .findViewById(R.id.likecountadapter);
        commentcount = (TextView) row
                .findViewById(R.id.commentcountadapter);
        viewHolder.tagImg = (ImageView) row
                .findViewById(R.id.tag_arrow);
        viewHolder.image1 = (ImageView) row
                .findViewById(R.id.image1);
        viewHolder.image2 = (ImageView) row
                .findViewById(R.id.image2);
        row.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) row.getTag();
    }
    mWishesData = wishListData.get(position);
    viewHolder.wishlikecount = mWishesData.getDeathWishLike();


    if ((position % 4) == 0) {
        viewHolder.lenear.setBackgroundColor(Color.rgb(255, 168, 0));
        viewHolder.back.setBackgroundResource(R.drawable.a2bg);
        viewHolder.tagImg.setBackgroundResource(R.drawable.a11);
        viewHolder.front.setBackgroundColor(Color.rgb(255, 168, 0));

    } else if ((position % 4) == 1) {
        viewHolder.lenear.setBackgroundColor(Color.rgb(253, 81, 43));
        viewHolder.back.setBackgroundResource(R.drawable.a3bg);
        viewHolder.tagImg.setBackgroundResource(R.drawable.a21);
        viewHolder.front.setBackgroundColor(Color.rgb(253, 81, 43));

        // viewHolder.Adlayout.invalidate();
        // viewHolder.Adlayout.setVisibility(View.GONE);
    } else if ((position % 4) == 2) {
        viewHolder.lenear.setBackgroundColor(Color.rgb(155, 89, 182));
        viewHolder.back.setBackgroundResource(R.drawable.a4bg);
        viewHolder.tagImg.setBackgroundResource(R.drawable.a31);
        viewHolder.front.setBackgroundColor(Color.rgb(155, 89, 182));

    } else if ((position % 4) == 3) {
        viewHolder.lenear.setBackgroundColor(Color.rgb(46, 204, 113));
        viewHolder.back.setBackgroundResource(R.drawable.a1bg);
        viewHolder.tagImg.setBackgroundResource(R.drawable.a41);
        viewHolder.front.setBackgroundColor(Color.rgb(46, 204, 113));
    }

ビューホルダー:

public static class ViewHolder {
    public int wishlikecount;
    public int wishcommentcount;
    LinearLayout back, lenear;
    RelativeLayout front;
    TextView deathWish;
    ImageButton likeButton, commentButton, shareButton, helpButton;
    TextView time, name, likecount;
    ImageView tagImg, image1, image2, profilePic;
}
4

1 に答える 1