如何显示“正在加载...”检索 ListView 项目时的文本
还有一些其他应用程序可以执行此操作,例如 Twitter、Facebook,甚至是 Android Market 等本机应用程序。当您想要显示从互联网检索到的项目列表时,这看起来像是向用户显示有关正在进行的操作的一些通知的标准方法。这是一个白色背景屏幕,带有动画旋转轮和“正在加载...”文本。
有人知道该怎么做吗?
我已经能够用这段代码做类似的事情,但我还不太喜欢它。仍在进行中:
<ListView android:id="@+id/post_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/loading"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" android:text="Loading..." />
There are some others applications doing this, like Twitter, Facebook, or even native applications such as Android Market. When you want to display a list of items retrieved from the internet, this looks like a standard way for displaying the user some notification about action in progress. This is a white background screen with an animated spinning wheel and a "Loading..." text.
Does somebody know how to do this?
I've been able to do something similar with this code, but I don't like it too much yet. Still work in progress:
<ListView android:id="@+id/post_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/loading"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" android:text="Loading..." />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是在 AsyncTask (智能后台)的帮助下完成的thread) 和 ProgressDialog
当 AsyncTask 启动时,我们提出一个进度对话框处于不确定状态,任务完成后我们将关闭该对话框。
示例代码
适配器在此示例中执行的操作并不重要,更重要的是要了解您需要使用 AsyncTask 来显示进度对话框。
That's done with the help of AsyncTask (an intelligent backround thread) and ProgressDialog
When the AsyncTask starts we reaise a progressdialog with indeterminate state, once the task is finished we dismiss the dialog.
Example code
What the adapter does in this example is not important, more important to understand that you need to use AsyncTask to display a dialog for the progress.
当用户滚动到底部时,适配器的 getView 应返回一个带有“正在加载..”文本和旋转进度的视图。同时,应启动 AsyncTask 或后台线程来下载新的内容块。当内容准备就绪时,调用adapter.notifyDatasetChanged(),并且ListView重新显示包括新项目在内的所有内容。
所以“正在加载...”消息只是 ListView 中的最后一项。
When user scrolls to the bottom your adapter's getView should return a view with "Loading.." text and spinning progress. At the same time AsyncTask or background thread should be started that downloads a new chunk of content. When content is ready adapter.notifyDatasetChanged() is called and ListView redisplays all content including the new items.
So "Loading..." message is just a last item in the ListView.
我不知道它是否完全符合您的要求,简单的方法是将加载文本最初设置为 android-empty-id-view
,如果没有找到列表项,则将 android-empty-id-view 设置为不同的消息异步回调
它将向用户提供足够的指示,表明某些事情正在进行中..即列表正在加载
I don't know whether it will completely fits your requirement, simple way is just set the loading text initially to android-empty-id-view like
and if no list items found then set android-empty-id-view to different message in async callback
it will give enough indication to user that something is progressing..i.e list is loading