Caldroid不会刷新 [英] Caldroid does not refresh

查看:175
本文介绍了Caldroid不会刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的onCreate 方法把Caldroid我这个code活性里面。

I have put Caldroid inside my activity with this code in onCreate method.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    app_font = Typeface.createFromAsset(getAssets(), "custom_font.ttf");
    dbHelper = new DatabaseHelper(this);
    caldroidFragment = new CaldroidFragment();
    if (savedInstanceState != null) {
        caldroidFragment.restoreStatesFromKey(savedInstanceState,
                "CALDROID_SAVED_STATE");
    } else {
        Bundle args = new Bundle();
        args.putInt(CaldroidFragment.MONTH, calendar.get(Calendar.MONTH) + 1);
        args.putInt(CaldroidFragment.YEAR, calendar.get(Calendar.YEAR));
        args.putBoolean(CaldroidFragment.ENABLE_SWIPE, true);
        args.putBoolean(CaldroidFragment.SIX_WEEKS_IN_CALENDAR, true);
        args.putInt(CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.MONDAY);
        caldroidFragment.setArguments(args);
    }
    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.replace(R.id.calendar_holder, caldroidFragment, FRAGMENT_TAG);
    t.commit();
    fragmentMounted = true;
    CaldroidListener listener = new CaldroidListener() {

        @Override
        public void onSelectDate(Date date, View view) {
            Intent k = new Intent(MainActivity.this, DateActivity.class);
            k.putExtra(TIME, date.getTime());
            MainActivity.this.startActivity(k);
        }

        @Override
        public void onChangeMonth(int month, int year) {
            if (marker != null) {
                marker.stopWorking();
            }
            marker = new DateMarker(MainActivity.this, month, year);
            marker.start();
        }

        @Override
        public void onLongClickDate(Date date, View view) {
            // do nothing
        }

        @Override
        public void onCaldroidViewCreated() {
            // do nothing
        }

    };
    caldroidFragment.setCaldroidListener(listener);
}

当你注意到,有一个被称为监听器里面,每次用户切换到其它月份。该线程访问具有事件数据库,并标记日期。

As you notice, there is a Thread being called inside listener every time user switches to other month. This thread accesses database and marks dates which have events.

请注意:这是code的该线程的run方法里面只是内部采样

NOTE: this is just inner sample of code inside run method of that thread.

// more code above
if (MainActivity.dbHelper.getNotesOnDate(date).size() == 0) {
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            activity.caldroidFragment.setBackgroundResourceForDate(R.color.SeaGreen, date);
            activity.caldroidFragment.setTextColorForDate(R.color.white, date);
            activity.caldroidFragment.refreshView();
        }
    });
}
//more code under

我开始为用户登录,而这一切的负荷另一个活动。问题是,只有那些之前的onCreate 法持有人认为更换片段做标记。我怎样才能刷新 caldroidFragment ,其持有人更换后? refreshView()似乎并没有把它放在后工作。

I start another activity for user to log in while all this loads. The problem is only markings that are made BEFORE replacing fragment with holder view in onCreate method. How can I refresh caldroidFragment after replacing it with its holder? refreshView() seems not to be working after placing it.

修改:我没有研究,我发现Caldroid使用的应用程序V4 片段。我试图拆卸并重新它得到刷新效果,但我只拿到了 NullPointerException异常试着去做。

EDIT: I did research and I notice Caldroid is using app V4 Fragment. I tried to detach and reattach it to get refresh effect but I only got NullPointerException while trying to do it.

推荐答案

我找到了答案,不要使用Java的日期类,它不工作的权利。

I found the answer, do not use Java's Date class, it does not work right.

使用乔达的的DateTime 。 Caldroid工作正常了。另外,我发现在我的数据库访问小错误,但尽管它在那里它应该甚至工作。

Use Joda's DateTime. Caldroid works fine with it. Also, I found minor bug in my database access, but it should have worked even though it was there.

这篇关于Caldroid不会刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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