我有一个应用程序,该应用程序从json获取数据并将其显示在回收站视图中,单击每个回收站视图时,它将打开一个新活动以显示完整内容。我只想知道在第二个活动表示感谢之前如何显示进度对话框。这是我的代码
public CustomViewHolder(View view, Context ctx, ArrayList<FeedItem> feeditem) {
super(view);
view.setOnClickListener(this);
this.ctx = ctx;
this.feeditem = feeditem;
this.imageView = (ImageView) view.findViewById(R.id.thumbnail);
this.textView2 = (TextView) view.findViewById(R.id.date);
this.textView3 = (TextView) view.findViewById(R.id.excerpt);
this.categories = (TextView) view.findViewById(R.id.categories);
this.textView = (TextView) view.findViewById(R.id.title);
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
FeedItem feeditem = this.feeditem.get(position);
Intent intent = new Intent(this.ctx, ScrollingActivity.class);
intent.putExtra("excerpt",feeditem.getExcerpt());
intent.putExtra("content",feeditem.getContent());
intent.putExtra("title",feeditem.getTitle());
Html.fromHtml(String.valueOf(intent.putExtra("content",feeditem.getContent()))).toString();
intent.putExtra("thumbnail",feeditem.getAttachmentUrl());
this.ctx.startActivity(intent);
}
您必须在第二个活动中处理它。在那里,您应该在后台线程中完成所有数据加载或繁重的处理工作,并在数据或处理完成时更新UI。
AsyncTask旨在完全满足此目的
public class LoadDataTask extends AsyncTask<Void, Void, Void> {
public LoadDataTask(ProgressDialog progress) {
this.progress = progress;
}
public void onPreExecute() {
progress.show();
}
public void doInBackground(Void... unused) {
... load your image here ...
}
public void onPostExecute(Void unused) {
progress.dismiss();
}
}
onPreExecute()
并onPostExecute()
在UI线程上运行。因此,您可以在此处更新UI,就像显示图像一样。
您的第二个活动现在应如下所示:
ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Loading...");
new LoadDataTask(progress).execute();
要获得更多帮助,请检查以下内容:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句