Custom Listview scroll hiding progressbar process and ImageView

前端 未结 5 783
予麋鹿
予麋鹿 2021-01-19 01:27

I have a custom Listview, where each item contains a progressbar. But when the list contains many items, and I use the scrollbar to navigate through listview, some ProgressB

5条回答
  •  深忆病人
    2021-01-19 02:02

    So for your ProgressBar.

    Whenever getView() is called, you set its visibility to GONE.

    holder.uploadProgressBar.setVisibility(View.GONE);
    

    So when starts to upload something (and sets uploadProgressBar to VISIBLE), and you scroll down (makes the list item invisible), then scroll up, getView() will be called again, and it will make your ProgressBar invisible.

    So you need wrap the state in an object, or use a list to record each item state. For example, in your ImageAdapter

    boolean[] uploadings = new boolean[getCount()];
    Arrays.fill(uploadings, false);
    

    in your getView()

    if (uploadings[position]) {
        // You need this, since you are not sure whether you are
        // using newly inflated view or ConvertView
        holder.uploadProgressBar.setVisibility(View.VISIBLE);
    } else {
        holder.uploadProgressBar.setVisibility(View.GONE);
    }
    

    And in your startUpload() method, whenever you set your prograss bar to GONE or VISIBILE, set uploadings[position] to false or true correspondingly.

    And I think your ImageView probably has the same problem.

提交回复
热议问题