为了账号安全,请及时绑定邮箱和手机立即绑定

如何从阿拉姆卡纳克安卓周视图库中的SQlite数据库获取所有事件?

如何从阿拉姆卡纳克安卓周视图库中的SQlite数据库获取所有事件?

慕娘9325324 2022-09-22 16:07:20

我正在尝试从我的SQLite数据库动态添加事件,但我在我的周视图中得到一个事件,这是我在数据库中添加的最后一个事件,我正在使用Lamkanak Week-View,我遇到了问题并尝试了许多方法,请帮助大家。


mWeekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {

        @Override

        public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {

            ArrayList<WeekViewEvent> lastevents = new ArrayList<WeekViewEvent>();

            lastevents = loadDateFromJson(newYear,newMonth);

               events.addAll(loadDateFromJson(newYear,newMonth));

                return events;

        }

    } );

}


 public ArrayList<WeekViewEvent> getmNewEvents(int year , int month ) {

    // Parse time.

    SimpleDateFormat sdf = new SimpleDateFormat("HH:MM");

    Date start = new Date();

    Date end = new Date();

    start = getMyTime();

    try {

        end = sdf.parse(new Event().getEndTime());

    } catch (ParseException e) {

        e.printStackTrace();

    }

    Calendar now = Calendar.getInstance();

    Calendar startTime = (Calendar) now.clone();

    startTime.setTimeInMillis(start.getTime());

    startTime.set(Calendar.YEAR, now.get(Calendar.YEAR));

    startTime.set(Calendar.MONTH, now.get(Calendar.MONTH));

    startTime.set(Calendar.DAY_OF_MONTH, getMyDate());

    Calendar endTime = (Calendar) startTime.clone();

    endTime.add(Calendar.HOUR_OF_DAY, 3);

创建周视图事件。


    ArrayList<WeekViewEvent> ThisMonthsEvents = new   ArrayList<WeekViewEvent>();

    WeekViewEvent weekViewEvent =new WeekViewEvent(1,"Raouf",startTime,endTime);

    mNewEvents.add(weekViewEvent);


for (int i = 0; i < mNewEvents.size(); i++) {

        mNewEvents.get(i).getStartTime().get(Calendar.MONTH);

        if((mNewEvents.get(i).getStartTime().get(Calendar.MONTH) == month)&&(mNewEvents.get(i).getStartTime().get(Calendar.YEAR) == year))

            ThisMonthsEvents.add(mNewEvents.get(i));

}


查看完整描述

1 回答

?
冉冉说

TA贡献1534条经验 获得超1个赞

我发现如何解决这个问题,我使用JSONArrays,它在这里工作得很好,也许有人会需要它!


public  List<WeekViewEvent> loadDateFromJson(int year , int month) {

        DBconexion dBconexion = new DBconexion(this);

        @SuppressLint("SimpleDateFormat") SimpleDateFormat sdfD = new SimpleDateFormat("yy-MM-dd");

        @SuppressLint("SimpleDateFormat") SimpleDateFormat sdfT = new SimpleDateFormat("HH:mm");

        try {

            JSONObject jo = dBconexion.getDateTime();

            JSONArray Datejason = jo.getJSONArray("Date");

            JSONArray Timejason = jo.getJSONArray("Time");

            JSONArray endTimejason = jo.getJSONArray("End Time");

            JSONArray Namejason = jo.getJSONArray("Name");

            for (int i = 0; i < Datejason.length(); i++) {

                //set date

                String sd = (String) Datejason.get(i);

                Date dfj = sdfD.parse(sd);

                int Day = dfj.getDate();

                int Month = dfj.getMonth() - 0;

                int Year = dfj.getYear();

                //set time

                String st = (String) Timejason.get(i);

                Date tfj = sdfT.parse(st);

                int Hour = tfj.getHours();

                int Minute = tfj.getMinutes();

                String endTimeP = (String) endTimejason.getString(i);

                int endTimePeriod = Integer.valueOf(endTimeP);

                //set name

                String Name = (String) Namejason.getString(i);

                //Rand Colors for Events

                Random rand = new Random();

                int r = rand.nextInt(255);

                int g = rand.nextInt(255);

                int b = rand.nextInt(255);

                int randomColor = Color.rgb(r,g,b);

                if(Color.rgb(r,g,b) == getResources().getColor(R.color.white)){

                   randomColor = getResources().getColor(R.color.red);

                }

                //Set StarTime

                Calendar startTime = Calendar.getInstance();

                startTime.set(Calendar.HOUR_OF_DAY, Hour);

                startTime.set(Calendar.MINUTE, Minute);

                startTime.set(Calendar.YEAR, year);

                startTime.set(Calendar.MONTH, Month);

                startTime.set(Calendar.DAY_OF_MONTH, Day);

                Calendar endTime = (Calendar) startTime.clone();

                endTime.add(Calendar.HOUR_OF_DAY, endTimePeriod);

                WeekViewEvent weekViewEvent = new WeekViewEvent(1, Name, startTime, endTime);

                weekViewEvent.setColor(randomColor);

                myEvent.add(weekViewEvent);

            }

        } catch (JSONException e) {

            e.printStackTrace();

        } catch (ParseException e) {

            e.printStackTrace();

        }

       return  myEvent;


    }

月数更改将如下所示


 mWeekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {

        @Override

        public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {


            List<WeekViewEvent> lastone = new ArrayList<WeekViewEvent> ();

            lastone = loadDateFromJson( newYear ,  newMonth);

             events.addAll(lastone);

            ArrayList<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();

            for (WeekViewEvent event : events) {

                if (eventMatches(event, newYear, newMonth)) {

                    matchedEvents.add(event);

                }

            }

            return matchedEvents;

        }

    } );


}


查看完整回答
反对 回复 2022-09-22

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信