我工作的一个Android应用程序,在应用程序我有intent2其上点击重定向到intent3和需要一些时间,然后加载一个表,并显示服务器数据到它。显示“加载:进度条”在Android的意图,直到数据加载
有时候,如果有大量的数据,它的故事非常的时间把数据加载和空白屏幕显示的时间增加。
我希望显示加载杆,直到数据负载。
我怎么能显示ProgrssBar直到只有在不显示的数据?
我工作的一个Android应用程序,在应用程序我有intent2其上点击重定向到intent3和需要一些时间,然后加载一个表,并显示服务器数据到它。显示“加载:进度条”在Android的意图,直到数据加载
有时候,如果有大量的数据,它的故事非常的时间把数据加载和空白屏幕显示的时间增加。
我希望显示加载杆,直到数据负载。
我怎么能显示ProgrssBar直到只有在不显示的数据?
可能是你最好的选择是使用的AsyncTask在“intent3”:
你可以做这样的:
private class performBackgroundTask extends AsyncTask <Void, Void, Void>
{
private ProgressDialog Dialog = new ProgressDialog(ClassName.this);
protected void onPreExecute()
{
Dialog.setMessage("Please wait...");
Dialog.show();
}
protected void onPostExecute(Void unused)
{
try
{
if(Dialog.isShowing())
{
Dialog.dismiss();
}
// do your Display and data setting operation here
}
catch(Exception e)
{
}
@Override
protected Void doInBackground(Void... params)
{
// Do your background data fetching here
return null;
}
}
你可能需要在打开上运行的onCreate一个的AsyncTask新的活动,该的AsyncTask的结构会是这样(从谷歌doc拍摄),请注意,如果你想increament一个进度条,你必须实现onProgressUpdate并调用publishProgress在doInBackground方法
private class DownloadFilesTask extends AsyncTask<Void, Integer, Void> {
protected void onPreExecute()
{
// show your progress bar
}
protected Void doInBackground(Void... params) {
// do your work and publish the progress
publishProgress(progress);
}
protected void onProgressUpdate(Integer... progress) {
setProgressPercent(progress[0]);
}
protected void onPostExecute(Void result) {
//dismiss your progress bar
}
}
这段代码只是一个例子,当然你需要将它适应你的逻辑/代码。
看看这个简单而完整example
,因为我已经扩展了活动课我不能延伸的AsyncTask。 – typedefcoder2
这应该是一个内部类,因此是私人的。然后你可以在你的onCreate中调用它。 – Andrei