我有ListView
每行都有一些小部件,我可以从Service
更新单行。更新行工作正常,但我无法INVISIBLE
或GONE
列表视图的行项。
例如,我的行有ImageView
和ProgressBar
。我不能在此代码中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
中的numberProgressBar
和iv_download_icon
无效。我正在测试和调试代码嵌套if
工作但是没有设置为窗口小部件
答案 0 :(得分:0)
我想你错过了notifyDatasetChnaged()
if (percent == 100) {
numberProgressBar.setVisibility(View.GONE);
iv_download_icon.setVisibility(View.GONE);
notifyDatasetChanged()
}
答案 1 :(得分:0)
我删除了这一行,问题解决了:
invalidateViews();