Android dynamic curriculum generation

Source: Internet
Author: User
Tags getcolor

Android dynamic curriculum generation

The curriculum is dynamically generated based on the provided course information. Unlike the online course schedule, the number of course segments is fixed, and the number of course segments in this course schedule is not fixed.

1,

There are 12 classes every day. The number of classes varies by day.

2. layout File Code

From Monday to Sunday, there are seven vertical linear layout files, all of which are auxiliary titles or serial numbers.

 

 
  
   
    
           
         
    
   
  
 
3. Size files used in layout files

 

 

 
     
  
   40dp
      
  
   2dp
      
  
   2dp
      
 
4. Color File

 

 

 
     
  
   #CCCCCC
      
  
   #ECECEC
      
  
   #6666CC
      
  
   #EDEDED
  
 
5. Style files

 

 

 
      
  
  
  
      
 

6. Course entity code

 

 

Package com. example. testcourse; public class Course {private String name, room, teach, id; // Course name, class classroom, instructor, Course No. int start, step; // start class times, public Course (String name, String room, int start, int step, String teach, String id) {super (); this. name = name; this. room = room; this. start = start; this. step = step; this. teach = teach; this. id = id;} public String getId () {return id;} public void setId (String id) {this. id = id;} public String getName () {return name;} public void setName (String name) {this. name = name;} public String getRoom () {return room;} public void setRoom (String room) {this. room = room;} public int getStart () {return start;} public void setStart (int start) {this. start = start;} public int getStep () {return step;} public void setStep (int step) {this. step = step;} public String getTeach () {return teach;} public void setTeach (String teach) {this. teach = teach ;}}

7. Activity code. As long as the course information is provided for 7 days, the course schedule can be automatically generated.

 

 

Package com. example. testcourse; import java. util. arrayList; import java. util. list; import android. OS. bundle; import android. app. activity; import android. graphics. color; import android. text. layout; import android. util. log; import android. view. gravity; import android. view. menu; import android. widget. linearLayout; import android. widget. textView; public class MainActivity extends Activity {LinearLayout weekPanels [] = new LinearLayout [7]; List courseData [] = new ArrayList [7]; int itemHeight; int marTop, marLeft; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // itemHeight = getResources (). getDimensionPixelSize (R. dimen. weekItemHeight); marTop = getResources (). getDimensionPixelSize (R. dimen. weekItemMarTop); marLeft = getResources (). getDimensionPixelSize (R. dimen. weekItemMarLeft); // data getData (); for (int I = 0; I <weekPanels. length; I ++) {weekPanels [I] = (LinearLayout) findViewById (R. id. weekPanel_1 + I); initWeekPanel (weekPanels [I], courseData [I]) ;}} public void getData () {List
 
  
List1 = new ArrayList
  
   
(); Course c1 = new Course (software engineering, A402, 1, 4, Dian Wei, 1002); list1.add (c1); list1.add (new Course (C language, A101, 6, 3, Gan Ning, 1001); courseData [0] = list1; List
   
    
List2 = new ArrayList
    
     
(); List2.add (new Course (Computer composition principles, A106, 6, 3, Ma Chao, 1001); courseData [1] = list2; List
     
      
List3 = new ArrayList
      
        (); List3.add (new Course (database theory, A105, 2, 3, Sun Quan, 1008); list3.add (new Course (computer network, A405, 6, 2, Sima Yi, 1009); list3.add (new Course (movie appreciation, A112, 9, 2, Zhuge Liang, 1039); courseData [2] = list3; List
       
         List4 = new ArrayList
        
          (); List4.add (new Course (data structure, A223, 1, 3, Liu Bei, 1012); list4.add (new Course (operating system, A405, 6, 3, Cao, 1014); courseData [3] = list4; List
         
           List5 = new ArrayList
          
            (); List5.add (new Course (Android development, C120, 1250, yellow cover, 1251); list5.add (new Course (game design principle, C120, Lu Xun )); courseData [4] = list5;} public void initWeekPanel (LinearLayout ll, List
           
             Data) {if (ll = null | data. size () <1) return; Log. I (Msg, initialization panel); Course pre = data. get (0); for (int I = 0; I <data. size (); I ++) {Course c = data. get (I); TextView TV = new TextView (this); LinearLayout. layoutParams lp = new LinearLayout. layoutParams (LinearLayout. layoutParams. FILL_PARENT, itemHeight * c. getStep () + marTop * (c. getStep ()-1); if (I> 0) {lp. setMargins (marLeft, (c. getStart ()-(pre. getStart () + pre. getStep () * (itemHeight + marTop) + marTop, 0, 0);} else {lp. setMargins (marLeft, (c. getStart ()-1) * (itemHeight + marTop) + marTop, 0, 0);} TV. setLayoutParams (lp); TV. setGravity (Gravity. TOP); TV. setGravity (Gravity. CENTER_HORIZONTAL); TV. setTextSize (12); TV. setTextColor (getResources (). getColor (R. color. courseTextColor); TV. setText (c. getName () ++ c. getRoom () ++ c. getTeach (); // TV. setBackgroundColor (getResources (). getColor (R. color. classIndex); TV. setBackground (getResources (). getDrawable (R. drawable. tvshape); ll. addView (TV); pre = c ;}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. activity_main, menu); return true ;}}
           
          
         
        
       
      
     
    
   
  
 





 

 

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.