3

私は現在、ここから LazyList ビューを使用しています: https://github.com/thest1/LazyList

すべてがうまく機能していますが、リストビューの初期ロードです。画像が読み込まれていません。画像を表示するには、実際に下にスクロールしてから戻る必要があります。以下は、私が使用しているアダプターのコードです。ここで何が間違っていますか?

更新:イメージビューのタグを取り出して役立つかどうかを確認しましたが、それでも同じ結果が得られることに注意してください。

public class BattleAdapter extends ArrayAdapter<Battle> {

private ArrayList<Battle> data = null;
private Context context;
private int layoutResourceId;
private ImageLoader imageLoader;

public BattleAdapter(Context context, int layoutResourceId,
        ArrayList<Battle> data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
    this.imageLoader = new ImageLoader(context);
}

static class BattleHolder {
    public CropImageView imageRight;
    public CropImageView imageLeft;
    public TextView displayNameRight;
    public TextView displayNameLeft;
    public TextView numComments;
    public TextView numVotes;
    public TextView timeLeft;
    public ImageView winnerImg1;
    public TextView winnerTxt1;
    public ImageView winnerImg2;
    public TextView winnerTxt2;
    public TextView tiedTxt1;
    public TextView tiedTxt2;
}

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

    BattleHolder holder = null;

    if (convertView == null) {

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        holder = new BattleHolder();

        convertView = inflater.inflate(R.layout.versus_list_item, null);
        holder.imageLeft = (CropImageView) convertView
                .findViewById(R.id.versus_challenger);
        holder.imageLeft.setClickable(false);
        holder.imageRight = (CropImageView) convertView
                .findViewById(R.id.versus_challenged);
        holder.imageRight.setClickable(false);
        holder.displayNameLeft = (TextView) convertView
                .findViewById(R.id.versus_challenger_name);
        holder.displayNameRight = (TextView) convertView
                .findViewById(R.id.versus_challenged_name);
        holder.numVotes = (TextView) convertView
                .findViewById(R.id.num_votes);
        holder.numComments = (TextView) convertView
                .findViewById(R.id.num_comments);
        holder.timeLeft = (TextView) convertView
                .findViewById(R.id.time_left);
        holder.winnerImg1 = (ImageView) convertView
                .findViewById(R.id.winner_img1);
        holder.winnerImg2 = (ImageView) convertView
                .findViewById(R.id.winner_img2);
        holder.winnerTxt1 = (TextView) convertView
                .findViewById(R.id.winner_img1_txt);
        holder.winnerTxt2 = (TextView) convertView
                .findViewById(R.id.winner_img2_txt);
        holder.tiedTxt1 = (TextView) convertView
                .findViewById(R.id.tie_txt1);
        holder.tiedTxt2 = (TextView) convertView
                .findViewById(R.id.tie_txt2);
        holder.timeLeft.setSelected(true);

        convertView.setTag(holder);
    } else {
        holder = (BattleHolder) convertView.getTag();
    }

    Battle battle = data.get(position);

    if (battle != null) {

        User challenger = battle.getChallenger();
        User challenged = battle.getChallenged();

        holder.displayNameLeft.setText(challenger.getDisplayName());

        holder.displayNameRight.setText(challenged.getDisplayName());

        holder.numComments.setText(Integer.toString(battle
                .getCommentCount()));
        holder.numVotes.setText(Integer.toString(battle.getVoteCount()));

        if (battle.getTimeLeft() != null) {

            if (battle.getTimeLeft().startsWith("-")) {
                holder.timeLeft.setText("Time's up. Calculating winner");
            } else if (battle.getTimeLeft().endsWith("responded")) {

                String newString = String.format(battle.getTimeLeft(),
                        challenged.getDisplayName());
                holder.timeLeft.setText(newString);

            } else
                holder.timeLeft.setText(battle.getTimeLeft());
        }

        imageLoader.DisplayImage(challenger.getPicPath(), holder.imageLeft);

        imageLoader.DisplayImage(challenged.getPicPath(), holder.imageRight);

        if (battle.getWinnerID() == -5) {
            holder.winnerImg1.setVisibility(View.VISIBLE);
            holder.winnerImg2.setVisibility(View.VISIBLE);
            holder.winnerTxt2.setVisibility(View.INVISIBLE);
            holder.winnerTxt1.setVisibility(View.INVISIBLE);
            holder.tiedTxt1.setVisibility(View.VISIBLE);
            holder.tiedTxt2.setVisibility(View.VISIBLE);
        }

        if (battle.getWinnerID() != 0 && battle.getWinnerID() != -1) {

            if (challenger.getUserID() == battle.getWinnerID()) {
                holder.winnerImg1.setVisibility(View.VISIBLE);
                holder.winnerTxt1.setVisibility(View.VISIBLE);
                holder.winnerImg2.setVisibility(View.VISIBLE);
                holder.winnerTxt2.setVisibility(View.INVISIBLE);
                holder.tiedTxt1.setVisibility(View.INVISIBLE);
                holder.tiedTxt2.setVisibility(View.INVISIBLE);

            }

            else if (challenged.getUserID() == battle.getWinnerID()) {
                holder.winnerImg2.setVisibility(View.VISIBLE);
                holder.winnerTxt2.setVisibility(View.VISIBLE);
                holder.winnerImg1.setVisibility(View.VISIBLE);
                holder.winnerTxt1.setVisibility(View.INVISIBLE);
                holder.tiedTxt1.setVisibility(View.INVISIBLE);
                holder.tiedTxt2.setVisibility(View.INVISIBLE);

            }
        }

        if (battle.getWinnerID() == 0 || battle.getWinnerID() == -1) {
            holder.winnerImg1.setVisibility(View.INVISIBLE);
            holder.winnerTxt1.setVisibility(View.INVISIBLE);
            holder.winnerImg2.setVisibility(View.INVISIBLE);
            holder.winnerTxt2.setVisibility(View.INVISIBLE);
            holder.tiedTxt1.setVisibility(View.INVISIBLE);
            holder.tiedTxt2.setVisibility(View.INVISIBLE);
            Log.i("BattleAdapter", "No winner");
        }

    }

    return convertView;
}
}
4

2 に答える 2