Use Recyclerview in Android studio to make a calendar that shows time-out

Source: Internet
Author: User

1. The user selects the date on the app side to be able to query this month's time clock information, and displays the different color on the calendar to display to the user, of course this calendar is Recyclerview made out, only each line displays 7, represents seven days of the week.

2. The data acquisition and analysis of the employee clock-in is done on the server side, through the application side of the date and user name, to complete the extraction of user attendance analysis, and return the results to the app, using WebService.

3. Bind the data and Recyclerview on the app side, use different colors for different results, that's it, the results are good.

The most critical part of the inside is 1.   Calculates the number of days of the month under the selected date. 2. The first day of the month is the days of the week, as the next, but also need to gradually improve, is July 2017

Knowing the two can be conveniently assembled on the. NET side of the calendar data and the first line of the offset came, the specific time analysis and return value, according to their own ideas to design the line, I am returning a simple string. The code is as follows.

Dim month as String = CDate (sdate). Month Dim Year as String = CDate (sdate). Year Dim days As Integer = Date.daysinmonth (year, month) Dim Szd as String = hr. Getgs (YHM) Dim Str As String = "" Dim img As String Dim k_rq As String = year & "-" & Month & Amp "-" & "1" Dim k_week as Integer = CDate (K_RQ).         DayOfWeek ' The first day of the month is the days of the week Dim Dt as DataTable = New DataTable Dt.Columns.Add ("date") Dt.Columns.Add ("Analysis") For i = 1 to K_week Dim dr as DataRow = Dt.newrow Dr. Item (0) = "" Dr.  Item (1) = "1-0" Dt.Rows.Add (DR) Next for i = 1 to days RQ = year & "-" & Month & "-" & I img = Kq_fenxi (RQ, Name, SZD) Dim dr as DataRow = Dt.newrow Dr. Item (0) = i dr. Item (1) = img Dt.Rows.Add (dr) Next Str = OA. Datatable2json (Dt) Return Str

  

The return value of the test is as follows, and the JSON is uploaded to the app for data binding.

<string xmlns= "http://tempuri.org/" >[{"date": "1", "Analysis": "1-0"},{"date": "2", "Analysis": "1-1"},{"date": "3", "Analysis": "1-1"},{" Date ":" 4 "," Analysis ":" 1-1 "},{" date ":" 5 "," Analysis ":" 1-2 "},{" date ":" 6 "," Analysis ":" 1-1 "},{" date ":" 7 "," Analysis ":" 1-1 "},{" date ":" 8 "," Analysis ":" 1-0 "},{" Date ":" 9 "," Analysis ":" 1-1 "},{" date ":" 10 "," Analysis ":" 1-1 "},{" date ":" 11 "," Analysis ":" 1-1 "},{" date ":" 12 "," Analysis ":" 1-1 "},{" date ":" 13 "," Analysis ":" 1-1 " },{"Date": "14", "Analysis": "1-1"},{"date": "15", "Analysis": "1-0"},{"date": "16", "Analysis": "1-3"},{"date": "17", "Analysis": "1-1"},{"date": "18", "Analysis": "1-1"},{"date": "19", "Analysis": "1-1"},{"date": "20", "Analysis": "1-1"},{"date": "21", "Analysis": "1-3"},{"date": "22", "Analysis": "1-0"},{"date": "23", "Analysis": "1-0"},{"date": "24", "Analysis": "1-1"},{"date": "25", "Analysis": "1-1"},{"date": "26", "Analysis": "1-1"},{"date": "27", "Analysis": "1-1"},{"date": "28", "Analysis": "1-1"},{"date": "29", "Analysis": "1-0"},{"date": "30", "Analysis": "1-1"},{"date": "31", "Analysis": "1-1"}]</string>

The following is the key part of Andriod studio, the code is as follows:

private void LoadData (String methodname,string cs1,string cs2) {try{WebService ws = New WebService (Met            HODNAME,CS1,CS2, "");            Ws.execute ();            LOG.E ("Kq-rq", CS1);            LOG.E ("Kq-uid", CS2);                    Ws.setonasyres (New Asyres () {@Override public void Ondaterec (String msg) {                    String Jsonstr;                    jsonstr=msg;                      LOG.E ("Kq-str", msg);                        try {mdatas=new arraylist<filelist> ();                        FileList map;                        Jsonarray Jsonarray = new Jsonarray (JSONSTR); for (int i = 0; i < jsonarray.length (); i++) {Jsonobject Jsonobject = Jsonarray.getjsonobje                            CT (i);                            Map=new FileList (jsonobject.getstring ("date"), jsonobject.getstring ("Analysis"));                        Mdatas.add (map); } myKqadapter recycler=new Mykqadapter (getactivity (), Mdatas);                          Recyclerview recyclerview= (Recyclerview) Vi.findviewbyid (r.id.lv_list);                          Linearlayoutmanager LayoutManager = new Linearlayoutmanager (getactivity ());Gridlayoutmanager girdmanger=new Gridlayoutmanager (getactivity (), 7);Recyclerview.setlayoutmanager (Girdmanger);                          If you can determine the height of each item is fixed, set this option to raise high performance recyclerview.sethasfixedsize (true); Create and set adapter Recyclerview.additemdecoration (new Myitemdec ());                          Add divider line Recyclerview.setadapter (recycler);                    Recyclerview.setitemanimator (New Defaultitemanimator ());        } catch (Jsonexception e) {}}}); }catch (Exception e) {}}

  

Increase the LOG.E, mainly to look at the parameters sent and return the result is correct, red code is to let Recyclerview each line display seven

In the custom data adapter, we parse the returned results and set different background colors based on the results.

 public void Onbindviewholder (Myviewholder holder, final int position) {FileList da=mdatas.get (position);        Holder.v.setbackgroundcolor (Color.White);        String msg=da.getmsg ();                if (listener! = null) {Holder.v.setonclicklistener (new View.onclicklistener () {@Override                public void OnClick (View v) {Listener.onitemclick (v,position);        }            });       }//Holder.tv.setGravity (gravity.center_horizontal);//Set text horizontally centered Holder.tv.setText (Da.getname ());        Holder.msg.setText ("");  if (Msg.equals ("1-1")) {Holder.v.setbackgroundcolor (color.green);        All day Work} if (Msg.equals ("1-2")) {Holder.v.setbackgroundcolor (Color.yellow);//half-day work} if (Msg.equals ("1-3")) {Holder.v.setbackgroundcolor (Color.yellow);//half-day work} if (Msg.equals ("1-0") ) {Holder.v.setbackgroundcolor (color.white);//Rest All day}   } 

Well, basically a calendar-based attendance screen is out, behind you can slowly add the table header, increase the click on the event, the user click on the display of detailed clock time.

Use Recyclerview in Android studio to make a calendar that shows time-out

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.