在片段Android上CursorLoader内显示进度对话框 [英] show Progress Dialog within a CursorLoader in a fragment android

查看:300
本文介绍了在片段Android上CursorLoader内显示进度对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,正如标题说,任何人都知道如何实现进度对话框,而从片段中的CursorLoader加载数据。找不到这方面的例子。如何做到这将是非常美联社preciated任何链接或指南。谢谢

Good day, as the title say, anyone know how to implement a progress dialog while loading data from a CursorLoader within a fragment. can't find any example in this regard. Any link or guide on how to do it will be highly appreciated. Thank you

推荐答案

我觉得@米哈尔的解决方案将是很好的显示通过 ProgressDialog#setIndeterminate一个不确定的ProgressDialog(真)所以我添加了一个+1。我不知道添加一个片段这样的片段(SomeFragment加入DialogFragment ..),因为我已经暗示类似的东西来之前SO上栽跟头被批准。另外,它的确定,该ProgressDialog用在这里,因为它终究是片段的组件从而片段属于下无需存在,作为一个独立的实体片段

I think @Michal's solution would be good for showing an indeterminate ProgressDialog via ProgressDialog#setIndeterminate(true) so I've added a +1. I'm not sure adding a Fragment to a Fragment like this (SomeFragment adding DialogFragment..) is approved as I've come a cropper on SO before suggesting something similar. Plus, it's ok that the ProgressDialog is used here since ultimately it is a component of the fragment thus belongs under the fragment without needing to exist as a separate Fragment entity.

要扩大这个答案,如果你想提供一个实时的最新进展的话,我会建议每一个工作单位后(最低分母工作,你可以算 CursorLoader 级别),你应该火焰通过 LocalBroadcastManger (保持局部的事件,没有人需要知道),你的片段将被监听。

To expand on this answer, if you were wanting to provide a real-time progress update then I would suggest that after each "unit of work" (the lowest denominator of work you can count at the CursorLoader level) you should fire an event via the LocalBroadcastManger (keep it local, no one else needs to know) which your Fragment will be listening for.

在片段的嵌套广播接收器#的onReceive()法下接收事件能得到你的碎片的 ProgressDialog 并增加与 incrementProgressBy(差异)或类似的显示进度。

On receiving the event under the Fragment's nested BroadcastReceiver#onReceive() method can get a reference to your Fragment's ProgressDialog and increment the displayed progress with incrementProgressBy(diff) or similar.

但是,如果你只是想弹出一个我做的事情对话框,然后设置ProgressDialog使用 setIndeterminate(真)就足够了。

If however, you just want to pop-up a "I'm doing something" dialog then setting the ProgressDialog to use setIndeterminate(true) will suffice.

最后,你有没有使用添加不确定的进度对话框的动作条的格局考虑?这是怎么了很多核心的应用程序,而底层 CursorLoader 正在运行。这将是很好的保持一致。查看关于 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)

Finally, have you considered using the pattern of adding the indeterminate progress dialog to the ActionBar? That is how a lot of the core apps operate whilst an underlying CursorLoader is working. It would be nice to keep it consistent. Check out items pertaining to requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS).

干杯。

更新

要达到你需要设置好你的父活动的最后一种方法(该位拥有的动作条)用类似code(我只是从内存中写这!);

To achieve the last approach you need to set-up your parent activity (the bit owning the ActionBar) with code similar to (I'm just writing this from memory!);

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Note that this is requested before you have called setContentView...
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.yourLayout);

在这一点上你说,我想在我的活动动作条的spinny进步的事。现在,这取决于你的活动执行,你可以选择以书面形式向显示的onCreate 不确定的进度条,立即

    setProgressBarIndeterminateVisibility(true);

但是,如果一个额外的行动会导致启动CursorLoader这可能是过于简单化。什么是重要的在这个练习中要注意的是,在在ActionBar进度对话框是与所属活动的一个特征的不可以您的基础片段。你不希望你的片段假设INDETERMINATE_PROGRESS功能已被要求自(一)它可能没有和(b)这不是它的prerogative明白这样的事情。换句话说,如果你发现自己写 getActivity()。setProgressBarIndeterminateVisibility(真)停下来思考。

But this may be too simplistic if an additional action causes the CursorLoader to be started. What is important to note throughout this exercise is that the progress dialog in the ActionBar is a feature of the owning activity and not your underlying Fragment. You don't want your fragment assuming that the INDETERMINATE_PROGRESS feature has been requested since (a) it may not have and (b) it's not it's prerogative to understand such things. In other words if you find yourself writing getActivity().setProgressBarIndeterminateVisibility(true) stop and think.

我想你应该充分利用更多的解耦方法,把底层的片段说:我已经开始执行负荷,让你的 CursorLoader 回调, onCreateLoader 类似;

I think you should leverage a more decoupled approach where the underlying Fragments says, "I have started to perform a load" so in your CursorLoader callback, onCreateLoader something like;

       @Override
       public Loader<Result> onCreateLoader(int id, Bundle b) {
        // Fire event saying this load is starting.
        final Intent loadStarted = new Intent();
        loadStarted.setAction(YourFragment.LOAD_STARTED);
        return new SomeCursorLoader(this.getActivity());
       }

您活动可以侦听此事件,然后当它接收到它,不确定的进度栏的可视性设置为true。

Your activity can be listening for this event and then when it receives it, sets the indeterminate progress bar visibility to true.

Similiarly,当 CursorLoader 回调, onLoaderFinished 被称为则触发另一个事件等;

Similiarly, when the CursorLoader callback, onLoaderFinished is called then fire another event like;

    @Override
    public void onLoadFinished(Loader<Result> loader, Result data) {
     // Fire event saying this load is finished.
     final Intent loadFinished = new Intent();
     loadFinished.setAction(YourFragment.LOAD_FINISHED);
    }

最后你的活动可以再套不确定的进度条可见为false onReceivie ING本次活动,光标结果显示给用户...

Finally your activity can then sets the indeterminate progress bar visibility to false onReceivieing this event and the cursor results are shown to the user...

这篇关于在片段Android上CursorLoader内显示进度对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆