目录
一、界面设计
fragment_blank.xml:
line_h.xml :
line_top.xml:
btn_bg_red.xml:
二、数据库的创建
Open_Sql.java:
三、数据库的使用
classcourse_json.java:
User_Data.java:
四、功能实现
BlankFragment.java:
DiaFragment.java:
styles.xml:
源代码地址:https://download.csdn.net/download/qq_17798399/10754331
这次我们来实现大学班级APP最主要的功能 课表查询
应该具备的子功能有:
表格的控件位置是按照课程节次和星期来命名的,如第三节课 星期一 是31,星期二是32;
>
>
>
>
>
>
>
这两个是表格线条样式
查询按钮的样式
那么目前为止,界面我们就写完了(简陋了点,先将就着用)。
package com.mobileshopdemo.qingyin.myapplicationclassdemo;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
* 创建数据库子类,继承自SQLiteOpenHelper类
* 需 复写 onCreat()、onUpgrade()
*/
public class Open_Sql extends SQLiteOpenHelper {
// 数据库版本号
private static Integer Version = 1;
//新建一个SQLiteOpenHelper的对象,在之后初始化时会用到
public static Open_Sql mySQLiteOpenHelp;
//设置你自己的数据库名称
public static final String DATABASE_NAME = "my.db";
/**
* 构造函数
* 在SQLiteOpenHelper的子类中,必须有该构造函数
*/
public Open_Sql(Context context, String name, SQLiteDatabase.CursorFactory factory,
int version) {
super(context, name, factory, version);
// 参数说明
// context:上下文对象
// name:数据库名称
// version:当前数据库的版本,值必须是整数并且是递增的状态
// 必须通过super调用父类的构造函数
}
/**
* 复写onCreate()
* 调用时刻:当数据库第1次创建时调用
* 作用:创建数据库 表 & 初始化数据
* SQLite数据库创建支持的数据类型: 整型数据、字符串类型、日期类型、二进制
*/
@Override
public void onCreate(SQLiteDatabase db) {
// 创建数据库1张表
// 通过execSQL()执行SQL语句(此处创建了1个名为classcourse的表)
String sql = "create table classcourse(id integer primary key autoincrement,name varchar(64),zhouci int(10),weizhi int(10))";
db.execSQL(sql);
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 6,11 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 7,11 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 8,11 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 10,11 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 2,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 3,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 4,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 5,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 6,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 7,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 8,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 9,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 10,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 11,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 12,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 13,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 14,21 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 2,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 3,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 4,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 5,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 6,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 7,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 8,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 10,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 11,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 12,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 13,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 14,12 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 2,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 3,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 4,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 5,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 6,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 7,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 8,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 9,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 10,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 11,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 12,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 13,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 14,22 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408',4 ,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408',6 ,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 10,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 11,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408', 12,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408',13 ,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '智能设备应用开发 3-408',14 ,13 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',2 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',3 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',4 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',6 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',7 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',8 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404', 10,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404', 11,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',12 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',13 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',14 ,23 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 2,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',3 ,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 4,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 6,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',7 ,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 8,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 10,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',11 ,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 12,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',13 ,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 14,33 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 2,14 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',4 ,14 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',6 ,14 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405', 8,14 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',10 ,14 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网项目实战 3-405',12 ,14 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 2,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 3,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',4 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',5 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',6 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',7 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 8,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',9 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 10,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',11 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',12 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',13 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',14 ,34 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',2 ,44 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',4 ,44 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',6 ,44 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',8 ,44 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',10 ,44 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',12 ,44 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404', 2,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',3 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',4 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',6 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',7 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404', 8,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',10 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',11 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',12 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',13 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '电子工程制图 3-404',14 ,25 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 2,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',3 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',4 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',5 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',6 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',7 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',8 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 9,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',10 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',11 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406', 12,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',13 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '物联网系统集成技术 3-406',14 ,35 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404', 2,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',3 ,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404', 4,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',6 ,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',7 ,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',8 ,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404', 10,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',11 ,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',12 ,45 )");
db.execSQL("insert into classcourse ( name, zhouci, weizhi) values ( '求职能力提升训练 3-404',14 ,45 )");
// 注:数据库实际上是没被创建 / 打开的(因该方法还没调用)
// 直到getWritableDatabase() / getReadableDatabase() 第一次被调用时才会进行创建 / 打开
}
/**
* 复写onUpgrade()
* 调用时刻:当数据库升级时则自动调用(即 数据库版本 发生变化时)
* 作用:更新数据库表结构
* 注:创建SQLiteOpenHelper子类对象时,必须传入一个version参数,该参数 = 当前数据库版本, 若该版本高于之前版本, 就调用onUpgrade()
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
课程信息可以爬学校系统的数据,不会的话也可以自己手动整理一下。
数据的封装我一开始打算用数据模型或者json之类的方法,后来还是选择直接用了set/get。
package com.mobileshopdemo.qingyin.myapplicationclassdemo;
public class classcourse_json {
private int id;
private String name;
private int zhouci;
private int weizhi;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getZhouci() {
return zhouci;
}
public void setZhouci(int zhouci) {
this.zhouci = zhouci;
}
public int getWeizhi() {
return weizhi;
}
public void setWeizhi(int weizhi) {
this.weizhi = weizhi;
}
public classcourse_json(int id, String name, int zhouci, int weizhi) {
super();
this.id = id;
this.name = name;
this.zhouci = zhouci;
this.weizhi = weizhi;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", zhouci=" + zhouci
+ ",weizhi=" + weizhi + "]";
}
}
接下来就是数据库的使用了
package com.mobileshopdemo.qingyin.myapplicationclassdemo;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class User_Data {
public Open_Sql dbHelper;
public SQLiteDatabase db;
Context mcontext;
public User_Data(Context context) {
this.mcontext = context;
// 创建DatabaseHelper对象
dbHelper = new Open_Sql(mcontext, "my.db", null, 1);
db = dbHelper.getWritableDatabase(); // 创建 or 打开 可读/写的数据库
}
public List find(Integer id) {
List classcourse_jsons = new ArrayList();
Open_Sql dbHelper1 = new Open_Sql(mcontext, "my.db", null, 1);
SQLiteDatabase db1 = dbHelper1.getReadableDatabase();
//查询部分数据
Cursor cursor = db1.rawQuery("select * from classcourse where zhouci = ?", new String[]{id.toString()});
if (cursor.moveToFirst() == false) {
Toast.makeText(mcontext, "您的CC表中无数据!!!", Toast.LENGTH_SHORT).show();
}
cursor.moveToFirst();
do {
//遍历保存数据
int name_id = cursor.getInt(cursor.getColumnIndex("id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int zhouci = cursor.getInt(cursor.getColumnIndex("zhouci"));
int weizhi = cursor.getInt(cursor.getColumnIndex("weizhi"));
classcourse_jsons.add(new classcourse_json(name_id, name, zhouci, weizhi));
} while (cursor.moveToNext());
cursor.close();
return classcourse_jsons;
}
}
package com.mobileshopdemo.qingyin.myapplicationclassdemo;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
/**
* 第一个页面 课表查询
*
* @author qingyin
*
*/
public class BlankFragment extends Fragment {
private static TextView mTx11;
private static TextView mTx12;
private static TextView mTx13;
private static TextView mTx14;
private static TextView mTx15;
private static TextView mTx21;
private static TextView mTx22;
private static TextView mTx23;
private static TextView mTx24;
private static TextView mTx25;
private static TextView mTx31;
private static TextView mTx32;
private static TextView mTx33;
private static TextView mTx34;
private static TextView mTx35;
private static TextView mTx41;
private static TextView mTx42;
private static TextView mTx43;
private static TextView mTx44;
private static TextView mTx45;
private static TextView mTx51;
private static TextView mTx52;
private static TextView mTx53;
private static TextView mTx54;
private static TextView mTx55;
private static TextView mTx61;
private static TextView mTx62;
private static TextView mTx63;
private static TextView mTx64;
private static TextView mTx65;
private static TextView mTxzhouci;
private View view;
private Button btn_show;
Context context;
User_Data ud;
List bf_classcourse_jsons = new ArrayList();
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_blank, container, false);
initview();
minitView();
time_week(getActivity());
return view;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getActivity();
}
//初始化控件
private void minitView() {
mTxzhouci = view.findViewById(R.id.zhouci);
mTx11 = view.findViewById(R.id.tx011);
mTx12 = view.findViewById(R.id.tx012);
mTx13 = view.findViewById(R.id.tx013);
mTx14 = view.findViewById(R.id.tx014);
mTx15 = view.findViewById(R.id.tx015);
mTx21 = view.findViewById(R.id.tx021);
mTx22 = view.findViewById(R.id.tx022);
mTx23 = view.findViewById(R.id.tx023);
mTx24 = view.findViewById(R.id.tx024);
mTx25 = view.findViewById(R.id.tx025);
mTx31 = view.findViewById(R.id.tx031);
mTx32 = view.findViewById(R.id.tx032);
mTx33 = view.findViewById(R.id.tx033);
mTx34 = view.findViewById(R.id.tx034);
mTx35 = view.findViewById(R.id.tx035);
mTx41 = view.findViewById(R.id.tx041);
mTx42 = view.findViewById(R.id.tx042);
mTx43 = view.findViewById(R.id.tx043);
mTx44 = view.findViewById(R.id.tx044);
mTx45 = view.findViewById(R.id.tx045);
mTx51 = view.findViewById(R.id.tx051);
mTx52 = view.findViewById(R.id.tx052);
mTx53 = view.findViewById(R.id.tx053);
mTx54 = view.findViewById(R.id.tx054);
mTx55 = view.findViewById(R.id.tx055);
mTx61 = view.findViewById(R.id.tx061);
mTx62 = view.findViewById(R.id.tx062);
mTx63 = view.findViewById(R.id.tx063);
mTx64 = view.findViewById(R.id.tx064);
mTx65 = view.findViewById(R.id.tx065);
}
public void deal_find(List classcourse_jsons, Context mcontext) {
int deal_weizhi;
String mTx;
for (classcourse_json cc_j : classcourse_jsons) {
deal_weizhi = cc_j.getWeizhi();
mTx = "tx0" + deal_weizhi;
//获得资源ID
int mTx_id = mcontext.getResources().getIdentifier("" + mTx, "id", mcontext.getPackageName());
switch (deal_weizhi) {
case 11:
mTx11.setText("" + cc_j.getName());
break;
case 12:
mTx12.setText("" + cc_j.getName());
break;
case 13:
mTx13.setText("" + cc_j.getName());
break;
case 14:
mTx14.setText("" + cc_j.getName());
break;
case 15:
mTx15.setText("" + cc_j.getName());
break;
case 21:
mTx21.setText("" + cc_j.getName());
break;
case 22:
mTx22.setText("" + cc_j.getName());
break;
case 23:
mTx23.setText("" + cc_j.getName());
break;
case 24:
mTx24.setText("" + cc_j.getName());
break;
case 25:
mTx25.setText("" + cc_j.getName());
break;
case 31:
mTx31.setText("" + cc_j.getName());
break;
case 32:
mTx32.setText("" + cc_j.getName());
break;
case 33:
mTx33.setText("" + cc_j.getName());
break;
case 34:
mTx34.setText("" + cc_j.getName());
break;
case 35:
mTx35.setText("" + cc_j.getName());
break;
case 41:
mTx41.setText("" + cc_j.getName());
break;
case 42:
mTx42.setText("" + cc_j.getName());
break;
case 43:
mTx43.setText("" + cc_j.getName());
break;
case 44:
mTx44.setText("" + cc_j.getName());
break;
case 45:
mTx45.setText("" + cc_j.getName());
break;
case 51:
mTx51.setText("" + cc_j.getName());
break;
case 52:
mTx52.setText("" + cc_j.getName());
break;
case 53:
mTx53.setText("" + cc_j.getName());
break;
case 54:
mTx54.setText("" + cc_j.getName());
break;
case 55:
mTx55.setText("" + cc_j.getName());
break;
case 61:
mTx61.setText("" + cc_j.getName());
break;
case 62:
mTx62.setText("" + cc_j.getName());
break;
case 63:
mTx63.setText("" + cc_j.getName());
break;
case 64:
mTx64.setText("" + cc_j.getName());
break;
case 65:
mTx65.setText("" + cc_j.getName());
break;
default:
break;
}
}
}
/*
获取系统日期
进入自动生成当日课表*/
public void time_week(Context con) {
Calendar calendar = Calendar.getInstance();
//获取系统的日期
//月
int month = calendar.get(Calendar.MONTH) + 1;
//日
int day = calendar.get(Calendar.DAY_OF_MONTH);
switch (month) {
case 9:
if (9 <= day && day <= 15) week_2(con);
else if (16 <= day && day <= 22) week_3(con);
else if (23 <= day && day <= 29) week_4(con);
else if (30 == day) week_5(con);
break;
case 10:
if (1 <= day && day <= 6) week_5(con);
else if (7 <= day && day <= 13) week_6(con);
else if (14 <= day && day <= 20) week_7(con);
else if (21 <= day && day <= 27) week_8(con);
else if (28 <= day && day <= 31) week_9(con);
break;
case 11:
if (1 <= day && day <= 3) week_9(con);
else if (4 <= day && day <= 10) week_10(con);
else if (11 <= day && day <= 17) week_11(con);
else if (18 <= day && day <= 24) week_12(con);
else if (25 <= day && day <= 30) week_13(con);
break;
case 12:
if (1 == day) week_13(con);
else if (2 <= day && day <= 8) week_14(con);
break;
}
}
public void week_2(Context con) {
mTxzhouci.setText("周次:二");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(2);
deal_find(bf_classcourse_jsons, con);
}
public static void clear_week(Context con) {
mTx11.setText("");
mTx12.setText("");
mTx13.setText("");
mTx14.setText("");
mTx15.setText("");
mTx21.setText("");
mTx22.setText("");
mTx23.setText("");
mTx24.setText("");
mTx25.setText("");
mTx31.setText("");
mTx32.setText("");
mTx33.setText("");
mTx34.setText("");
mTx35.setText("");
mTx41.setText("");
mTx42.setText("");
mTx43.setText("");
mTx44.setText("");
mTx45.setText("");
mTx51.setText("");
mTx52.setText("");
mTx53.setText("");
mTx54.setText("");
mTx55.setText("");
mTx61.setText("");
mTx62.setText("");
mTx63.setText("");
mTx64.setText("");
mTx65.setText("");
}
public void week_3(Context con) {
mTxzhouci.setText("周次:三");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(3);
deal_find(bf_classcourse_jsons, con);
}
public void week_4(Context con) {
mTxzhouci.setText("周次:四");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(4);
deal_find(bf_classcourse_jsons, con);
}
public void week_5(Context con) {
mTxzhouci.setText("周次:五");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(5);
deal_find(bf_classcourse_jsons, con);
}
public void week_6(Context con) {
mTxzhouci.setText("周次:六");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(6);
deal_find(bf_classcourse_jsons, con);
}
public void week_7(Context con) {
mTxzhouci.setText("周次:七");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(7);
deal_find(bf_classcourse_jsons, con);
}
public void week_8(Context con) {
mTxzhouci.setText("周次:八");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(8);
deal_find(bf_classcourse_jsons, con);
}
public void week_9(Context con) {
mTxzhouci.setText("周次:九");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(9);
deal_find(bf_classcourse_jsons, con);
}
public void week_10(Context con) {
mTxzhouci.setText("周次:十");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(10);
deal_find(bf_classcourse_jsons, con);
}
public void week_11(Context con) {
mTxzhouci.setText("周次:十一");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(11);
deal_find(bf_classcourse_jsons, con);
}
public void week_12(Context con) {
mTxzhouci.setText("周次:十二");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(12);
deal_find(bf_classcourse_jsons, con);
}
public void week_13(Context con) {
mTxzhouci.setText("周次:十三");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(13);
deal_find(bf_classcourse_jsons, con);
}
public void week_14(Context con) {
mTxzhouci.setText("周次:十四");
ud = new User_Data(con);
bf_classcourse_jsons = ud.find(14);
deal_find(bf_classcourse_jsons, con);
}
public void initview() {
// mtitle=view.findViewById(R.id.text_title);
btn_show = view.findViewById(R.id.butselect1);
btn_show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DiaFragment.newInstance().show(getChildFragmentManager(), "dialog");
}
});
}
@Override
public void onStart() {
super.onStart();
}
}
查询功能:
package com.mobileshopdemo.qingyin.myapplicationclassdemo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class DiaFragment extends DialogFragment {
Button a0001;
Button a0002;
Button a0003;
Button a0004;
Button a0005;
Button a0006;
Button a0007;
Button a0008;
Button a0009;
Button a00010;
Button a00011;
Button a00012;
Button a00013;
View view;
View.OnClickListener mylistener = null;
public static DiaFragment newInstance() {
Bundle args = new Bundle();
DiaFragment fragment = new DiaFragment();
fragment.setCancelable(true);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.dialog);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//点击空白处返回
getDialog().setCanceledOnTouchOutside(true);
view = inflater.inflate(R.layout.activity_diffent_dialog, null, false);
this.a0001 = view.findViewById(R.id.a0001);
this.a0002 = view.findViewById(R.id.a0002);
this.a0003 = view.findViewById(R.id.a0003);
this.a0004 = view.findViewById(R.id.a0004);
this.a0005 = view.findViewById(R.id.a0005);
this.a0006 = view.findViewById(R.id.a0006);
this.a0007 = view.findViewById(R.id.a0007);
this.a0008 = view.findViewById(R.id.a0008);
this.a0009 = view.findViewById(R.id.a0009);
this.a00010 = view.findViewById(R.id.a00010);
this.a00011 = view.findViewById(R.id.a00011);
this.a00012 = view.findViewById(R.id.a00012);
this.a00013 = view.findViewById(R.id.a00013);
final BlankFragment bf=new BlankFragment();
View.OnClickListener mylistener = new View.OnClickListener() {
@Override
public void onClick(View a) {
switch (a.getId()) {
case R.id.a0001:
BlankFragment.clear_week(getActivity());
bf.week_2(getActivity());
dismiss();
break;
case R.id.a0002:
BlankFragment.clear_week(getActivity());
bf.week_3(getActivity());
dismiss();
break;
case R.id.a0003:
BlankFragment.clear_week(getActivity());
bf.week_4(getActivity());
dismiss();
break;
case R.id.a0004:
BlankFragment.clear_week(getActivity());
bf.week_5(getActivity());
dismiss();
break;
case R.id.a0005:
BlankFragment.clear_week(getActivity());
bf.week_6(getActivity());
dismiss();
break;
case R.id.a0006:
BlankFragment.clear_week(getActivity());
bf.week_7(getActivity());
dismiss();
break;
case R.id.a0007:
BlankFragment.clear_week(getActivity());
bf.week_8(getActivity());
dismiss();
break;
case R.id.a0008:
BlankFragment.clear_week(getActivity());
bf.week_9(getActivity());
dismiss();
break;
case R.id.a0009:
BlankFragment.clear_week(getActivity());
bf.week_10(getActivity());
dismiss();
break;
case R.id.a00010:
BlankFragment.clear_week(getActivity());
bf.week_11(getActivity());
dismiss();
break;
case R.id.a00011:
BlankFragment.clear_week(getActivity());
bf.week_12(getActivity());
dismiss();
break;
case R.id.a00012:
BlankFragment.clear_week(getActivity());
bf.week_13(getActivity());
dismiss();
break;
case R.id.a00013:
BlankFragment.clear_week(getActivity());
bf.week_14(getActivity());
dismiss();
break;
default:
break;
}
}
};
a0001.setOnClickListener(mylistener);
a0002.setOnClickListener(mylistener);
a0003.setOnClickListener(mylistener);
a0004.setOnClickListener(mylistener);
a0005.setOnClickListener(mylistener);
a0006.setOnClickListener(mylistener);
a0007.setOnClickListener(mylistener);
a0008.setOnClickListener(mylistener);
a0009.setOnClickListener(mylistener);
a00010.setOnClickListener(mylistener);
a00011.setOnClickListener(mylistener);
a00012.setOnClickListener(mylistener);
a00013.setOnClickListener(mylistener);
return view;
}
}
查询页面:
activity_diffent_dialog.xml:
到这我们的课表项目就实现了,如果有出现问题的话可以下载源码或留言讨论