Android实验报告基于文件的日程安排.docx
- 文档编号:10312804
- 上传时间:2023-05-25
- 格式:DOCX
- 页数:12
- 大小:17.15KB
Android实验报告基于文件的日程安排.docx
《Android实验报告基于文件的日程安排.docx》由会员分享,可在线阅读,更多相关《Android实验报告基于文件的日程安排.docx(12页珍藏版)》请在冰点文库上搜索。
Android实验报告基于文件的日程安排
第三次实验基于文件的日程安排
一.实验目的及实验环境
1.实验目的
1)掌握首选项方式的存储和读取
2)掌握位于内存上的数据文件的存储和读取
3)掌握位于SD卡上的数据文件的存储和读取
2.实验环境
系统开发平AndroidStudio
系统开发平台:
Android
运行平台:
WindowsXP及以上
运行环境:
FrameworkSDK
二.实验教材、组织方式、实验内容
1.实验教材:
Andorid开发与应用
2.组织方式:
个人独立完成
2.实验内容:
实现基于文件存储的日程安排应用,数据文件可以保存在机身内存或者SD卡中。
通过单击增加图标打开新增加活动界面,通过单击保存按钮将活动内容写入到文件中,并返回前页,点击删除图标,可以删除该活动。
(保存或删除须给出提示框)
三.方案设计
写了一个三个界面,一个是已经安排的活动的界面,一个是新增加活动的界面,还有一个是浏览界面,然后增加活动的时候调用了日期选择框,对日期进行选择,然后对时间进行选择,选择之后,输入记录,然后写入文件存储起来,
下次打开app可以查看之前记录的内容。
四.运行结果
五.总结
通过这次实验掌握了首选项方式的存储和读取,掌握了位于内存上的数据文件的存储和读取以及位于SD卡上的数据文件的存储和读取
六.附录:
源代码
import
importclassMainActivityextendsActivity{
privateList
privateListViewlistview;
privateMyAdapteradapter;
protectedvoidonCreate(BundlesavedInstanceState){
(savedInstanceState);
setContentViewlist=newArrayList
list=query();
listview=(ListView)findViewByIdadapter=newMyAdapter();
(adapter);
}
publicList
{
List
Stringstr="";
FileInputStreamfis;
try{
fis=openFileInput("");
byte[]buffer=newbyte[()];
(buffer);
str=newString(buffer);
();
}catch(Exceptione)
{}
String[]array=("\n");
for(inti=0;i<;i++)
{
Stringst=array[i];
(st);
}
returnlist;
}
publicvoidaddImage(Viewview)
{
Intentintent=newIntent();
intent=newIntent,;
startActivity(intent);
}
privateclassMyAdapterextendsBaseAdapter
{
publicintgetCount(){
return();
}
publicObjectgetItem(intposition){
return(position);
}
publiclonggetItemId(intposition){
returnposition;
}
publicViewgetView(intposition,ViewconvertView,ViewGroupparent)
{
Viewview=convertView!
=null?
convertView:
(getApplicationContext(),null);
TextViewactivity=(TextView)finalStringname=(position);
());
ImageViewdelete=(ImageView)(new(){
publicvoidonClick(Viewarg0){
new
.setTitle("确定要删除吗?
")
.setPositiveButtonnew(){
publicvoidonClick(DialogInterfacedialog,intwhich){
(name);
Stringstr="";
notifyDataSetChanged();
for(inti=0;i<();i++)
{
str+=(i).toString()+"\n";
}
FileOutputStreamfos;
try{
fos=openFileOutput("",MODE_PRIVATE);
());
();
}catch(Exceptione)
{
();
}
}
})
.setNegativeButtonnew(){
publicvoidonClick(DialogInterfacedialog,intwhich){
();
}
})
.show();
}
});
returnview;
}
}
}
xmlversion=""encoding="utf-8"?
>
android="" android: layout_width="match_parent" android: layout_height="wrap_content" android: scrollbarSize="1dip"> android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="vertical"> --ToDoItemtask--> android: id="@+id/itemTaskLabel" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/item_task_text" android: textSize="22sp"/> android: id="@+id/itemTaskEditText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: layout_gravity="left" android: hint="@string/addItemHint" android: lines="6"/> android: layout_width="fill_parent" android: layout_height="1px" android: background="? android: attr/listDivider"/> --ToDoItemtime--> android: id="@+id/itemTimeLabel" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/item_time_text" android: textSize="22sp"/> style="? android: attr/buttonBarStyle" android: layout_width="match_parent" android: layout_height="wrap_content" android: orientation="horizontal" android: padding="0dip"> android: layout_width="fill_parent" android: layout_height="1px" android: background="? android: attr/listDivider"/> --ToDoItemalertTime--> android: id="@+id/alertLayout" android: layout_width="match_parent" android: layout_height="wrap_content" android: padding="5dip"> android: id="@+id/itemAlertLabel" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/item_alert_text" android: textSize="22sp"/> android: id="@+id/itemAlertTime" android: layout_width="fill_parent" android: layout_height="wrap_content" android: layout_below="@+id/itemAlertLabel" android: textSize="14sp"/> android: id="@+id/itemAlertImageView" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_alignParentRight="true" android: layout_centerVertical="true" android: contentDescription="@string/item_duplicate_contentDescription" android: src="@drawable/add"/> android: id="@+id/alertTableLayout" android: layout_width="fill_parent" android: layout_height="0dip" android: layout_marginLeft="5dip" android: layout_weight="1" android: padding="5dip" android: stretchColumns="0,1"> android: layout_width="fill_parent" android: layout_height="1px" android: background="? android: attr/listDivider"/> --ToDoItemduplicate--> android: id="@+id/duplicateLayout" android: layout_width="match_parent" android: layout_height="wrap_content" android: padding="5dip"> android: id="@+id/itemDuplicateLabel" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/item_duplicate_text" android: textSize="22sp"/> android: id="@+id/itemDuplicate" android: layout_width="fill_parent" android: layout_height="wrap_content" android: layout_below="@+id/itemDuplicateLabel" android: textSize="14sp"/> android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_alignParentRight="true" android: layout_centerVertical="true" android: contentDescription="@string/item_duplicate_contentDescription" android: src="@drawable/arrow_right"/> android: layout_width="fill_parent" android: layout_height="1px" android: background="? android: attr/listDivider"/> --ToDoItempriority--> android: id="@+id/priorityLayout" android: layout_width="match_parent" android: layout_height="wrap_content" android: padding="5dip"> android: id="@+id/itemPriorityLabel" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/item_priority_text" android: textSize="22sp"/> android: id="@+id/itemPriority" android: layout_width="fill_parent" android: layout_height="wrap_content" android: layout_below="@+id/itemPriorityLabel" android: textSize="14sp"/> android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_alignParentRight="true" android: layout_centerVertical="true" android: contentDescription="@string/item_duplicate_contentDescription" android: src="@drawable/arrow_right"/> android: layout_width="fill_parent" android: layout_height="1px" android: background="? android: attr/listDivider"/> xmlversion=""encoding="utf-8"? >
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 实验 报告 基于 文件 日程安排