Android实验一实验报告.docx
- 文档编号:11791523
- 上传时间:2023-04-01
- 格式:DOCX
- 页数:13
- 大小:16.71KB
Android实验一实验报告.docx
《Android实验一实验报告.docx》由会员分享,可在线阅读,更多相关《Android实验一实验报告.docx(13页珍藏版)》请在冰豆网上搜索。
Android实验一实验报告
Companynumber:
【0089WT-8898YT-W8CCB-BUUT-202108】
Android实验一实验报告
Android实验报告一
姓名:
丁军峰
班级:
信科12-3
学号:
08123448
一、实验内容
编写一个Android应用程序,实现对自己物品的管理,功能包括添加、删除和查询等
二、实验目的
了解android开发流程,掌握SQLite数据库和ListView控件的使用
三、需求分析
使用SQLite数据库,使用ListView控件显示物品
四、实验过程
1.创建程序,设计用户交互界面
android= android: layout_width="match_parent" android: layout_height="match_parent" android: orientation="vertical"> android: layout_width="match_parent" android: layout_height="0dp" android: layout_weight="1" android: orientation="vertical"> android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="物品清单" /> android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="horizontal"> android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="物品名称"/> android: id="@+id/id_et_stuffname" android: layout_width="match_parent" android: layout_height="wrap_content" android: inputType="text"/> android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="horizontal"> android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="物品个数"/> android: id="@+id/id_et_stuffamount" android: layout_width="match_parent" android: layout_height="wrap_content" android: inputType="text"/> android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="horizontal"> android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="物品价格"/> android: id="@+id/id_et_stuffprize" android: layout_width="match_parent" android: layout_height="wrap_content" android: inputType="text"/> android: layout_width="match_parent" android: layout_height="wrap_content" > android: layout_width="match_parent" android: layout_height="match_parent" android: orientation="horizontal"> android: layout_width="match_parent" android: layout_height="1dp" android: background="#eee"/> 2.创建ListViewItem布局 android= android: layout_width="match_parent" android: layout_height="match_parent" android: orientation="horizontal" android: background="#ffffffff"> android: id="@+id/id_ig_name" android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: src="@drawable/ic_menu_paste_holo_light"/> android: id="@+id/id_tv_name" android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: textColor="#000000" android: textSize="18sp"/> android: id="@+id/id_tv_amount" android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: textColor="#000000" android: textSize="18sp"/> android: id="@+id/id_tv_price" android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: textColor="#000000" android: textSize="18sp"/> android: id="@+id/id_ib_delete" android: layout_width="0dp" android: layout_height="wrap_content" android: layout_weight="1" android: src="@drawable/ic_menu_delete" android: background="#ffffffff" android: onClick="deleteItem"/> 3.创建数据库 packageclassMySQLiteOpenHelperextendsSQLiteOpenHelper{ publicMySQLiteOpenHelper(Contextcontext ){ super(context,"",null,1); 建account类 packageclassStuff{ privateStringstuffName; privateintStuffAmount; privatefloatStuffPrice; publicStringgetStuffName(){ returnstuffName; } publicvoidsetStuffName(StringstuffName){ =stuffName; } publicintgetStuffAmount(){ returnStuffAmount; } publicvoidsetStuffAmount(intstuffAmount){ StuffAmount=stuffAmount; } publicfloatgetStuffPrice(){ returnStuffPrice; } publicvoidsetStuffPrice(floatstuffPrice){ StuffPrice=stuffPrice; } } 5.创建数据操作逻辑 packageclassStuffListextendsActivity{ privateListViewlv; privateSQLiteDatabasemDataBase; privateList privateMySQLiteOpenHelpermHelper; @Override protectedvoidonCreate(BundlesavedInstanceState){ mHelper=newMySQLiteOpenHelper(this); all(); (savedInstanceState); } publicvoidall(){ mDataBase=(); Cursorcursor=("LIQI",null,null,null,null,null,null); stuffInfos=newArrayList while()){ Stuffstuff=newStuff(); (1)); (2)); (3)); (stuff); } (); (); (newMyadapter()); } classMyadapterextendsBaseAdapter{ @Override publicintgetCount(){ return(); } @Override publicObjectgetItem(intposition){ etStuffName()); ("数量(个)"+(position).getStuffAmount()); ("单价(元)"+(position).getStuffPrice()); (newOnClickListener(){ @Override publicvoidonClick(Viewv){ mDataBase=(); ("LIQI","stuff=",newString[]{(position).getStuffName()}); (); (position); } }); returnview; } } } 6.编写界面交互代码 packageclassMainActivityextendsActivityimplementsOnClickListener{ privateMySQLiteOpenHelpermHelper; privateSQLiteDatabasemDataBase; privateButtonbt_add,bt_all; privateEditTextet_stuffName,et_stuffAmount,et_stuffPrice; @Override protectedvoidonCreate(BundlesavedInstanceState){ (savedInstanceState); mHelper=newMySQLiteOpenHelper(this); initView(); initAction(); } publicvoidinitView(){ } publicvoidinitAction(){ (this); (this); } @Override publicvoidonClick(Viewv){ switch()){ add(); break; Intentintent=newIntent(this,; startActivity(intent); break; } } publicvoidadd(){ StringstuffName=().toString().trim(); intstuffAmount=().toString().trim()); floatstuffPrice=().toString().trim()); Stuffstuff=newStuff(); (stuffName); (stuffAmount); (stuffPrice); mDataBase=(); ContentValuescontentValues=newContentValues(); ("stuff",()); ("amount",()); ("price",()); longnumber=("LIQI",null,contentValues); if(number==-1){ (this,"添加失败",1).show(); }else{ (""); (""); (""); (this,"添加成功,物品条数"+number,1).show(); } (); } } android= package="" android: versionCode="1" android: versionName=""> android: minSdkVersion="8" android: targetSdkVersion="17"/> android: allowBackup="true" android: icon="@drawable/ic_launcher" android: label="@string/app_name" > android: name=".MainActivity" android: label="@string/app_name"> name=/> name=/> name=""> 五、实验结果 程序界面显示
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 实验 报告