0

此类扩展 baseadapter

public View getView(int position, View convertView, ViewGroup parent) {
    if (!imagepath[position].toString().equals("no picture")) {
        imageLoader.DisplayImage(imagepath[position], imageview);
    }
}

public void DisplayImage(String url, ImageView imageView) {
    imageViews.put(imageView, url);
    Bitmap bitmap = memoryCache.get(url);
    if (bitmap != null) {
        imageView.setImageBitmap(bitmap);
    } else {
        queuePhoto(url, imageView);
    }
}

假设第一个视图应该首先检查仅显示,但现在检查后显示。

if (!imagepath[position].toString().equals("no picture")) {

        titletext.setPadding(imageview.getWidth() + 5, 0, 0, 0);
        datetext.setPadding(imageview.getWidth() + 5, 0, 0, 0);
        imageview.setVisibility(View.VISIBLE);
        imageLoader.DisplayImage(imagepath[position], imageview);
    } else {
        imageview.setVisibility(View.INVISIBLE);
        imageview.setImageDrawable(null);
        titletext.setPadding(0, 0, 0, 0);
        datetext.setPadding(0, 0, 0, 0);
    }

    titletext.setText(title[position].toString());
    categorytext.setText(category[position].toString());
    datetext.setText(date[position].toString());

我希望 textview setpadding 首先只显示而不是相反。

如何解决这个问题?

4

1 回答 1

6

这是因为ListView重用了Views, put else 条件

public View getView(int position, View convertView, ViewGroup parent) {
    if (!imagepath[position].toString().equals("no picture")) {
        imageLoader.DisplayImage(imagepath[position], imageview);
    }
    else{
        imageview.setImageResource(android.R.color.transparent);
        // OR
        imageview.setImageDrawable(null);
    }
}
于 2012-05-10T05:42:51.583 回答