团队作业-第四周-面向对象程序设计

移动课堂点名APP

  一、程序源码涉及多个类,比较繁杂,就不贴到这儿了,在这附上源代码地址:https://github.com/WreckBear/final

  二、该程序涉及以下几个类,对以下的类进行简要说明:  

      CallNameActivity:显示全局点名的界面。
      CallNameAll:负责点名选择界面。
      CallNameRdmActivity:负责随机点名界面。
      CountActivity:负责统计界面。
      ImportActivity:负责导入文件的界面。
      MainActivity:主界面。
      MoreActivity:更多界面。
      MyDBOpenHelper:关于和数据库交互的类。
      MyInfoActivity:我的信息页。
      PersonDao:关于数据库请求类。
      SplashActivity:进入Splash界面。

  三、部分代码

      贴出统计页面的源码,简要说明下思路:

        本类包含4个方法:oncreate():初始化界面的各个变量。

                  onstart():检测有无表kecheng1存在,如存在则调用count方法;否则就显示没有课程。

                  tableExist():检测数据表是否存在。

                  count():将所有同学的数据从数据库中取出来,放到listview中显示。

      下面是具体代码,附注释:

 3 import java.awt.Cursor;
 4 import java.util.ArrayList;
 5 import java.util.HashMap;
 6 import java.util.List;
 7 
 8  public class CountActivity extends Activity {
 9      ListView listView;
10      TextView text;
11      LinearLayout linearLayout;
12 
13     @Override
14      protected void onCreate(Bundle savedInstanceState) {
15          super.onCreate(savedInstanceState);
16          setContentView(R.layout.count_layout);
17  
18          //初始化界面组件
19          text = (TextView) findViewById(R.id.toast);
20          linearLayout = (LinearLayout) findViewById(R.id.instudct);
21          listView = (ListView) findViewById(R.id.count);
22      }
23  
24      @Override
25      protected void onStart() {
26         super.onStart();
27         //如果表存在,就调用count方法
28          if (tabIsExist("kecheng1")) {
29              linearLayout.setVisibility(View.VISIBLE);
30             listView.setVisibility(View.VISIBLE);
31              text.setVisibility(View.GONE);
32              count();
33         } else {
34              linearLayout.setVisibility(View.GONE);
35              listView.setVisibility(View.GONE);
36             text.setVisibility(View.VISIBLE);
37          }
38     }
39  
40      public boolean tabIsExist(String tabName) {
41          SQLiteDatabase dbInfo = new MyDBOpenHelper(this).getReadableDatabase();
42          boolean result = false;
43          if (tabName == null) {
44             return false;
45          }
46          Cursor cursor = null;
47          try {
48              String sql = "select count(*) as c from sqlite_master where type ='table' and name ='"
49                      + tabName.trim() + "' ";
50              cursor = dbInfo.rawQuery(sql, null);
51              if (cursor.moveToNext()) {
52                  int count = cursor.getInt(0);
53                  if (count > 0) {
54                      result = true;
55                  }
56              }
57          } catch (Exception e) {
58          } finally {
59              dbInfo.close();
60          }
61          return result;
62      }
63  
64      private void count() {
65          // 存放数据用
66          List<HashMap<String, String>> all = new ArrayList<HashMap<String, String>>();
67          PersonDao per = new PersonDao(this);
68          List<String[]> tmpList = per.getAllPerson();
69          //将数据拆箱装到hashmap里
70          for (String[] tmpAll : tmpList) {
71              HashMap hash = new HashMap<String, String>();
72              hash.put("学号", tmpAll[0]);
73              hash.put("班级", tmpAll[3]);
74             hash.put("姓名", tmpAll[1]);
75              hash.put("缺勤", tmpAll[4]);
76              all.add(hash);
77          }
78          //设置listViw适配器
79          SimpleAdapter simple = new SimpleAdapter(this, all, R.layout.liststyle,
80                  new String[] { "学号", "班级", "姓名", "缺勤" }, new int[] { R.id.t1,
81                          R.id.t2, R.id.t3, R.id.t4 });
82          listView.setAdapter(simple);
83  
84      }
85  }