Android:如何自动刷新UI上的元素(无需刷新整个屏幕)
I want to refresh my tile after clicking on a Download all button. I m using GridAdapter to display a grids for multiple videos. So If i click on Download all Button tile grid should show a progress bar, But currently it is not showing without refreshing the entire page.
单击“全部下载”按钮后,我想刷新我的磁贴。我使用GridAdapter显示多个视频的网格。因此,如果我点击下载所有按钮磁贴网格应显示进度条,但目前它没有显示没有刷新整个页面。
We have tried below mentioned code on button click event but application getting crashed.....
我们在按钮点击事件上尝试了下面提到的代码但应用程序崩溃了.....
handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
File tempfile = new File(mContext.getExternalFilesDir(course_name),productCode);
if(tempfile.exists()){
viewHolder.mProgressBar.setVisibility(View.VISIBLE);
iewHolder.mImageView.setVisibility(View.INVISIBLE);
}else{
File tempthumbfile = new File(mContext.getExternalFilesDir(course_name),fname);
Log.d("tempthumbfile-->",""+tempthumbfile);
if(tempthumbfile.exists()){
viewHolder.mImageView.setBackgroundDrawable(Drawable.createFromPath(new File(mContext.getExternalFilesDir(course_name),fname).getAbsolutePath()));
}
viewHolder.mProgressBar.setVisibility(View.INVISIBLE);
viewHolder.mImageView.setVisibility(View.VISIBLE);
}
handler.postDelayed(this, 2000);
}
}, 1500);
2 个解决方案
#1
Your question is not very specific, but try the following two approaches:
您的问题不是很具体,但请尝试以下两种方法:
1) First and foremost, if you want to refresh a specific tile in your grid. Just call TileAdapter.notifyDataSetChanged();
1)首先,如果要刷新网格中的特定图块。只需调用TileAdapter.notifyDataSetChanged();
2) If you are trying to e.g. blur the entire Grid and show a loading bar on top of it. Find a reference to the View hosting the grid and call view.invalidate();
2)如果您正在尝试例如模糊整个网格并在其上显示加载栏。查找托管网格的View的引用并调用view.invalidate();
更多相关文章
- 按下子活动后退按钮后,Android主要活动的元素不响应
- JSP页面中有一个按钮 点击之后执行JAVA文件
- 不幸的是,在声明按钮时,模拟器中出现了错误
- 单击按钮后更改Frame的内容窗格
- 在Java中选择showMessageDialog框右上角的x按钮退出系统?