- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 AsyncTask 在加载 Rss 新闻时显示进度条。因为这是我第一次使用 asyncTask 我不知道我的方法是否正确,所以你能告诉我它对你来说是否合适?它正在工作,但我只想保持安静!谢谢
public class BackgroundAsyncTask_nea extends
AsyncTask<Void, Void, Void> {
private ProgressDialog dialog;
int myProgress;
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
displayRss();
dialog.dismiss();
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
dialog = ProgressDialog.show(nea.this, "", "Loading. Please wait...", true);
myProgress = 0;
}
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
//super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
loadFeed();
return null;
}
}
loadFeed();
private void loadFeed(){
try{
BaseFeedParser parser = new BaseFeedParser();
messages = parser.parse();
}
catch (Throwable t){
Log.e("OSFP.News",t.getMessage(),t);
finish();
}
}
displayRss();
private void displayRss(){
ArrayList<HashMap<String, String>> List_nea = new ArrayList<HashMap<String, String>>(messages.size());
for (Message msg : messages){
des.add(msg.getDescription());// keimeno
text.add(msg.getTitle());// titlos
url.add(msg.getLink());// link
imgl.add(msg.getImgLink());
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", msg.getTitle());
map.put("date", msg.getDate());
List_nea.add(map);
ListAdapter mSchedule = new SimpleAdapter(this, List_nea, R.layout.row,
new String[] {"name", "date"}, new int[] {R.id.TextView01, R.id.TextView02});
this.setListAdapter(mSchedule);
}
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(400);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(400);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
ListView listViewn = getListView();
listViewn.setLayoutAnimation(controller);
}
最佳答案
为了更新进度条,您需要调用 publishProgress()功能。您没有在代码中的任何地方这样做。如果我是你,我会将 AsyncTask 的引用传递到你的 loadFeed 函数中。像这样:
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
loadFeed(this);
return null;
}
private void loadFeed(AsyncTask<Void, Void, Void> asyncTask){
// make calls to publishProgress in here.
try{
BaseFeedParser parser = new BaseFeedParser();
messages = parser.parse();
}
catch (Throwable t){
Log.e("OSFP.News",t.getMessage(),t);
finish();
}
}
您还需要实现您尚未实现的 onProgressUpdate()
方法。这是您实际更新进度条值的地方。
protected void onProgressUpdate(Integer... progress) {
dialog.setProgress(progress[0]);
}
关于android - 如何使用AsyncTask显示ProgressBar和加载Rss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8297947/
我的应用程序中有一个 ProgressBar 小部件,无论我做什么,它总是显示为粗橙色(2.x 样式)而不是细蓝色(4.x 样式) . 项目构建目标设置为 Google API 4.0.3(API 级
private static ProgressDialog pDialog; pDialog = new ProgressDialog(activity); pDialog.setIndetermin
我试图让 TalkBack 阅读进度条上的进度,但运气不佳。关于如何获取该信息以便 TalkBack 可以说出来的任何想法。 谢谢 公共(public)类 MainActivity 扩展 Activi
进度条总是返回null public void calcola(View view) { final Dialog myDialog = new Dialog(this);
我正在尝试用选取框样式测试进度条,但没有成功 private void Form1_Load(object sender, EventArgs e) { Applica
我使用以下 Ruby 片段下载 a 8.9MB file . require 'open-uri' require 'net/http' require 'uri' def http_download
我为操作栏按钮尝试了两种不同的进度条样式,通过 refreshMenuItem.setActionView(R.layout.actionbar_indeterminate_progress); ac
每当我输入 fragment 时,我都会看到几秒钟的空白,然后 WebView 中的网页就会出现。 ProgressBar 好像没有显示。 这是我的 XML 文件,用于 WebView 和 Progr
我的包依赖于一个名为 progressbar 的包。有一个bug in progressbar 2.3导致Python>3.3安装失败,因此我安装了latest git repo from this
任何默认的 ProgressBar 都有一个 ClipDrawable 级别,例如,一个绿色的 Drawable 在我的设备上填充灰色背景,在其他设备上填充黄色。 我的问题:当进度小于最大值时,是否可
这是随意的原型(prototype)代码,因此我尝试了我认为应该有效的方法,如果没有,则在谷歌上搜索,然后在仔细阅读类似问题后在这里提问。 我的 Shell 中有以下标记看法:
要在执行查询时显示 ProgressBar,我使用以下代码: if not Query1.Prepared then Query1.Prepare; Query1.Open; ProgressBa
我有三个类,例如 View 、逻辑、 Controller 。 class View{ Progressbutton pb; void start animation(){
我正在用 C#/WPF(.Net 框架 4.0)编写一个应用程序。我遇到的一件事是如何在应用程序非常繁忙时更新控件(如果可能)。我想我只是在努力尝试我在网上找到的东西来让它工作(而且在极少数情况下它会
要在执行查询时显示 ProgressBar,我使用以下代码: if not Query1.Prepared then Query1.Prepare; Query1.Open; ProgressBa
已关闭。此问题不符合 Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 已关闭 3 年前。 奥 git _a
我创建了一个 ping 程序来 ping 5 服务器。如何在进度运行时让进度条运行。当 ping 完成时,进度条将为 100% private void btnGetstatusActionPer
我想在流程完成后在 PrimeFaces 上隐藏一个进度条。我认为没有必要在不工作时显示进度条。 html代码:
我想添加JProgressBar,它将在下载文件的程序中填充。 第三个问题是如何使进度条在 setValue 中添加正确的金额(例如:当它下载最后一个文件时,JPB 将完成)。 请注意,要下载的文件数
给定一个变量 N,反射(reflect)秒数,我想要一个 jQueryUI Progressbar顺利地从空更新到反射(reflect)该时间段内的完成。 换句话说,我想要一个显示进度条的functi
我是一名优秀的程序员,十分优秀!