更新行

时间:2015-07-12 05:44:36

标签: android listview android-listview

我有ListView每行都有一些小部件,我可以从Service更新单行。更新行工作正常,但我无法INVISIBLEGONE 列表视图的行项

例如,我的行有ImageViewProgressBar。我不能在此代码中INVISIBLE这个小部件

private void updateView(int download_item_id, int position, int percent, final String stream_filename, final String thumb_path) {
        Log.e("receive: thumb_path: ", thumb_path);
        View v = UI.lv_message_content.getChildAt(position - UI.lv_message_content.getFirstVisiblePosition());
        UI.lv_message_content.getAdapter().getView(position, v, UI.lv_message_content);
        UI.lv_message_content.invalidateViews();
        if (v == null) return;

        ImageView         imgv_image_item   = (ImageView) v.findViewById(R.id.imgv_image_item);
        NumberProgressBar numberProgressBar = (NumberProgressBar) v.findViewById(R.id.npb_progressbar);
        ImageView         iv_download_icon  = (ImageView) v.findViewById(R.id.iv_download_icon);
        numberProgressBar.setProgress(percent);

        if (percent == 100) {
            numberProgressBar.setVisibility(View.GONE);
            iv_download_icon.setVisibility(View.GONE);
        }
    }
如果百分比等于100,那么代码View.GONE中的numberProgressBariv_download_icon无效。我正在测试和调试代码嵌套if工作但是没有设置为窗口小部件

2 个答案:

答案 0 :(得分:0)

我想你错过了notifyDatasetChnaged()

if (percent == 100) {
     numberProgressBar.setVisibility(View.GONE);
     iv_download_icon.setVisibility(View.GONE);
     notifyDatasetChanged()
}

答案 1 :(得分:0)

我删除了这一行,问题解决了:

invalidateViews();