diff --git a/students/net1814080903122/report/lab5.md b/students/net1814080903122/report/lab5.md new file mode 100644 index 000000000..0d15e55df --- /dev/null +++ b/students/net1814080903122/report/lab5.md @@ -0,0 +1,121 @@ +# 实验五 + +## 一、实验目标 + +1.了解Andoid的存储手段; +2.掌握Android的文件存储; +3.掌握Android的数据库存储. + +## 二、实验内容 + +1. 将应用产生的数据存储到数据库 +2. 使用数据库存储 + +## 三、实验步骤 + +代码如下: + +``` +package edu.hzuapps.androidlabs.model; + +import android.app.Application; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +import java.lang.reflect.Method; +import java.util.ArrayList; + +import edu.hzuapps.androidlabs.bean.ScheduleItem; + +public class SchedulesModel { + private static ArrayList itemArrayList = new ArrayList<>(); + private static int count = 0; + private static SQLiteDatabase db = null; + private static SchedulesModel schedulesModel = new SchedulesModel(); + private SchedulesModel(){ + String dbPath = ApplicationGetter.getCurApplication().getFilesDir().getAbsolutePath() + "schedule.db"; + db = SQLiteDatabase.openOrCreateDatabase(dbPath,null); + seekorCreateTable(); + } + + private void seekorCreateTable(){ + StringBuilder sql = new StringBuilder("create table if not exists schedule("); + sql.append("_id integer primary key autoincrement,"); + sql.append("date text NOT NULL,"); + sql.append("message text NOT NULL)"); + db.execSQL(sql.toString()); + count = count(); + initItemArray(); + } + + public static SchedulesModel getInstance(){ + return schedulesModel; + }; + public int getCount() { return count; } + + private int count() { + Cursor cursor = db.query("schedule", null, null, null, null, null, null); + int count = cursor.getCount(); + cursor.close(); + return count; + } + + + public static Object getItem(int position) { + return itemArrayList.get(position); + } + + + private void initItemArray(){ + Cursor cursor = db.query("schedule", null, null, null, null, null, null); + if (cursor.moveToFirst()) { + int i = 0; + ScheduleItem item; + do { + item = new ScheduleItem(cursor.getInt(0),cursor.getString(1),cursor.getString(2)); + itemArrayList.add(item); + }while(cursor.moveToNext()); + } + } + + private static class ApplicationGetter{ + public static Application getCurApplication(){ + Application application = null; + try{ + Class atClass = Class.forName("android.app.ActivityThread"); + Method currentApplicationMethod = atClass.getDeclaredMethod("currentApplication"); + currentApplicationMethod.setAccessible(true); + application = (Application) currentApplicationMethod.invoke(null); + Log.d("fw_create","curApp class1:"+application); + }catch (Exception e){ + Log.d("fw_create","e:"+e.toString()); + } + + if(application != null) + return application; + try{ + Class atClass = Class.forName("android.app.AppGlobals"); + Method currentApplicationMethod = atClass.getDeclaredMethod("getInitialApplication"); + currentApplicationMethod.setAccessible(true); + application = (Application) currentApplicationMethod.invoke(null); + Log.d("fw_create","curApp class2:"+application); + }catch (Exception e){ + Log.d("fw_create","e:"+e.toString()); + } + return application; + } + } +} + +``` + +## 四、实验结果截图 + +可以新增运动计划 + +![lab5](lab5.png) + +## 五、实验心得 + +通过这次实验学会了Andorid中的存储手段,这次使用了数据库存储,并掌握数据库存储。 \ No newline at end of file diff --git a/students/net1814080903122/report/lab5.png b/students/net1814080903122/report/lab5.png new file mode 100644 index 000000000..dc1dc070c Binary files /dev/null and b/students/net1814080903122/report/lab5.png differ diff --git a/students/net1814080903122/report/lab6(1).jpg b/students/net1814080903122/report/lab6(1).jpg new file mode 100644 index 000000000..58a6b9ce9 Binary files /dev/null and b/students/net1814080903122/report/lab6(1).jpg differ diff --git a/students/net1814080903122/report/lab6.jpg b/students/net1814080903122/report/lab6.jpg new file mode 100644 index 000000000..2cf811afd Binary files /dev/null and b/students/net1814080903122/report/lab6.jpg differ diff --git a/students/net1814080903122/report/lab6.md b/students/net1814080903122/report/lab6.md new file mode 100644 index 000000000..4fc7b1e85 --- /dev/null +++ b/students/net1814080903122/report/lab6.md @@ -0,0 +1,487 @@ +# 实验六 Android网络编程 + +## 一、实验目标 + + + +1.掌握Android的网络访问方法; + +2.理解XML和JSON表示数据的方法。 + +## 二、实验内容 + + + +1.在个人目录中创建一个表示数据的XML或JSON文件; + +2.数据文件代码提交之后从GitHub获取文件URL; + +3.在应用中通过网络编程访问GitHub的数据文件; + +4.在应用中解析并显示文件所包含的数据; + +5.将应用运行结果截图。 + +## 三、实验步骤 + +1.建立activity_file_download.xml; + +activity_file_download.xml代码: + + ```xml + + +