Android开发之Eclipse制作简易备忘录.docx

上传人:b****3 文档编号:10209409 上传时间:2023-05-24 格式:DOCX 页数:22 大小:56.16KB
下载 相关 举报
Android开发之Eclipse制作简易备忘录.docx_第1页
第1页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第2页
第2页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第3页
第3页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第4页
第4页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第5页
第5页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第6页
第6页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第7页
第7页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第8页
第8页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第9页
第9页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第10页
第10页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第11页
第11页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第12页
第12页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第13页
第13页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第14页
第14页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第15页
第15页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第16页
第16页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第17页
第17页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第18页
第18页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第19页
第19页 / 共22页
Android开发之Eclipse制作简易备忘录.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Android开发之Eclipse制作简易备忘录.docx

《Android开发之Eclipse制作简易备忘录.docx》由会员分享,可在线阅读,更多相关《Android开发之Eclipse制作简易备忘录.docx(22页珍藏版)》请在冰点文库上搜索。

Android开发之Eclipse制作简易备忘录.docx

Android开发之Eclipse制作简易备忘录

Android开发之Eclipse制作“备忘录"

备忘录,或者说是便签,其实界面设计比较简单,机载的一些便签也是比较简单的设计,当然,如果想让画面更加绚丽点,可以融合进相应技术,在这里,我就做一些简单的设计.界面之外,主要是文件的存储与读取,设计到java编程的IO流操作,相信对于有着一定的java基础的人都是很容易去理解的.

UI图如下:

下面简单介绍一下我制作这个备忘录的过程。

首先做UI设计,具体设计相信只是时间问题,很好解决,直接编写xml布局文件,对于该备忘录,我设计了3个xml布局文件,其中第一个是activity_main.xml,第二个是about.xml(里面存放的是copyrights信息),第三个是details.xml(里面是用于显示某条选中记录的完整信息),三个布局分别如下:

除了第一个布局,另外两个布局都有back按钮,用于返回到主界面。

三个布局的布局文件应该是很容易写的,需要注意的是,需要设置响应的id,以便在主函数中进行消息响应。

三个布局文件的代码分别是:

activity_main.xml

android=”

xmlns:

tools=”

android:

layout_width=”match_parent”

android:

layout_height=”match_parent"

android:

paddingBottom=”@dimen/activity_vertical_margin”

android:

paddingLeft="@dimen/activity_horizontal_margin”

android:

paddingRight=”@dimen/activity_horizontal_margin"

android:

paddingTop="@dimen/activity_vertical_margin"

tools:

context=”com.example.xiongyanan.notes。

MainActivity"〉

〈EditText

android:

id=”@+id/et_content"

android:

layout_width=”match_parent”

android:

layout_height=”wrap_content"

android:

layout_alignParentLeft=”true”

android:

layout_alignParentTop="true”

android:

layout_marginLeft="10dp”

android:

layout_marginRight=”10dp"

android:

layout_marginTop=”0dp”

android:

background=”#D9CAC4"

android:

gravity=”top”

android:

maxLines=”4”

android:

lines="4"

android:

maxLength=”110”

android:

textColor=”#FD0516"/>

android:

id=”@+id/bt_write"

android:

textColor="#541717"

android:

layout_width=”wrap_content”

android:

layout_height=”wrap_content”

android:

width=”35dp”

android:

layout_alignLeft="@+id/et_content"

android:

layout_below="@+id/et_content”

android:

layout_marginTop="10dp"

android:

text=”write"/>

〈LinearLayout

android:

id="@+id/linearLayout1”

android:

layout_alignParentLeft=”true”

android:

layout_marginLeft="15dp”

android:

layout_marginRight="15dp”

android:

layout_width=”match_parent"

android:

layout_height="wrap_content"

android:

layout_below="@id/bt_write"

android:

layout_marginTop="5dp"

android:

orientation="vertical">

〈TextView

android:

id="@+id/note_saved1"

android:

clickable="true"

android:

layout_width=”match_parent"

android:

layout_height="wrap_content”

android:

background="#96C8A8”

android:

layout_marginBottom="5dp"

android:

textColor="#177C50"

android:

lines=”1”

android:

textSize="20dp”/>

〈TextView

android:

id=”@+id/note_saved2”

android:

layout_width="match_parent"

android:

layout_height="wrap_content"

android:

background=”#96C8A8”

android:

layout_marginBottom=”5dp"

android:

textColor=”#177C50”

android:

textSize=”20dp”

android:

lines="1”

android:

clickable="true”/〉

〈TextView

android:

id=”@+id/note_saved3"

android:

clickable=”true”

android:

layout_width=”match_parent”

android:

background="#96C8A8”

android:

layout_height="wrap_content”

android:

layout_marginBottom="5dp”

android:

textColor=”#177C50”

android:

lines=”1"

android:

textSize=”20dp”/>

android:

id="@+id/note_saved4”

android:

clickable=”true"

android:

layout_width=”match_parent"

android:

layout_height=”wrap_content”

android:

background=”#96C8A8”

android:

layout_alignLeft="@+id/linearLayout1"

android:

layout_below=”@+id/linearLayout1”

android:

layout_marginBottom=”5dp”

android:

textColor=”#177C50"

android:

lines="1"

android:

textSize="20dp"/〉

android:

id="@+id/note_saved5"

android:

clickable="true”

android:

layout_width="match_parent”

android:

layout_height="wrap_content"

android:

background=”#96C8A8”

android:

layout_alignLeft="@+id/textView2"

android:

layout_below="@+id/textView2”

android:

layout_marginBottom="5dp”

android:

textColor="#177C50”

android:

lines="1"

android:

textSize="20dp”/>

〈/LinearLayout>

android:

id=”@+id/bt_save"

android:

layout_width=”wrap_content”

android:

layout_height=”wrap_content”

android:

layout_above=”@+id/linearLayout1"

android:

layout_toRightOf="@+id/bt_write"

android:

clickable=”true"

android:

text="save"

android:

textColor=”#541717”

android:

width="35dp”/>

android:

id="@+id/bt_rewrite”

android:

layout_width="wrap_content"

android:

layout_height="wrap_content”

android:

layout_alignBottom="@+id/bt_save”

android:

layout_alignTop="@+id/bt_save”

android:

layout_toRightOf="@+id/bt_save"

android:

shadowColor="#263646"

android:

text=”clear"

android:

textColor="#541717”

android:

width="40dp"/〉

android:

id=”@+id/bt_about”

android:

layout_width="wrap_content”

android:

layout_height="wrap_content"

android:

layout_above=”@+id/linearLayout1"

android:

layout_alignRight="@+id/linearLayout1”

android:

layout_alignTop=”@+id/bt_rewrite”

android:

layout_toRightOf=”@+id/bt_rewrite"

android:

text=”about"

android:

textColor=”#541717”

android:

width=”35dp”/〉

〈Button

android:

id="@+id/bt_down”

android:

layout_width=”wrap_content"

android:

layout_height="wrap_content”

android:

layout_alignLeft="@+id/linearLayout1"

android:

layout_below=”@+id/linearLayout1”

android:

text=”down”/>

android:

id="@+id/bt_up"

android:

layout_width="wrap_content”

android:

layout_height="wrap_content”

android:

layout_alignBaseline="@+id/bt_down”

android:

layout_alignBottom=”@+id/bt_down”

android:

layout_alignRight="@+id/linearLayout1"

android:

text=”up”/〉

android:

id=”@+id/bt_first"

android:

layout_width=”wrap_content"

android:

layout_height="wrap_content"

android:

layout_alignBaseline=”@+id/bt_up"

android:

layout_alignBottom=”@+id/bt_up”

android:

layout_centerHorizontal=”true"

android:

text="first”/〉

〈/RelativeLayout>

detail.xml:

:

〈?

xmlversion=”1。

0”encoding="utf—8”?

>

android=”http:

//schemas。

android:

layout_width="match_parent”

android:

layout_height="match_parent">

〈TextView

android:

id=”@+id/tv_details”

android:

layout_height=”wrap_content"

android:

layout_width="match_parent"

android:

maxLines="8"

android:

textColor="#2E37AA"

android:

textSize=”20dp”

android:

lines=”8”

android:

text="hello"/〉

android:

id="@+id/bt_back"

android:

layout_width=”wrap_content”

android:

layout_height="wrap_content"

android:

layout_alignParentRight=”true"

android:

layout_below=”@+id/tv_details"

android:

layout_marginRight="16dp”

android:

layout_marginTop=”46dp”

android:

text=”back”/〉

〈/RelativeLayout〉

至此,界面布置完成,相应的控件ID都已合理的设置,接下来,需要写主函数以及用于IO存储的函数。

下面对诸多按钮的功能进行一一叙述:

“write”——设置光标可见,设置编辑区清空

“save"——存储TextView(也就是编辑框)里的内容到相应的xxx.txt里面,该txt文件将存储在手机内存中。

“clear”——backspace的作用

“about"--作者信息与app信息

“up”——记录向上滚动

“down”——记录向下滚动

“first”——首页

按下每个小TextView时,将进入记录具体内容演示界面,其中按下“back”将返回主界面.

功能补述:

:

由于记录是存储在手机内存中的,因此,希望每次启动app时候,能载入已经存储好了的记录,且按照习惯,载入最近的几条记录,并可实现记录翻页取出.因此,文件既涉及到存,也涉及到读,为实现存储文件和读取文件,编写noteService类,里面包含读、写函数,具体代码如下:

publicclassnoteService

{

publicstaticbooleansaveContent(Contextcontext,Stringcontent,intsaveCountor)

Stringstr=”content"+saveCountor;

try

Filefile=newFile(context。

getFilesDir(),str);

FileOutputStreamfos=newFileOutputStream(file);

fos.write((content).getBytes());

fos。

close();

returntrue;

}catch(Exceptione){

e.printStackTrace();

returnfalse;

publicstaticStringgetSavedContent(Contextcontext,intsaveCountor){

Stringstr=”content”+saveCountor;

Filefile=newFile(context.getFilesDir(),str);

try{

FileInputStreamfis=newFileInputStream(file);

BufferedReaderbr=newBufferedReader(newInputStreamReader(fis));

Stringstr1=br。

readLine();

returnstr1;

}

catch(Exceptione){

e。

printStackTrace();

returnnull;

}

}

此类中没有定义实例化对象函数。

定义好noteService类后,接下来需要编写主函数了。

为了实现上述功能,主函数需要对相应事件进行监听,进行相应的处理,并力争减少bug,顾经过反复调试,主类代码为:

packagecom.example。

xiongyanan.notes;

importjava.io。

File;

importandroid.os。

Bundle;

importandroid。

support。

v7。

app.ActionBarActivity;

importandroid。

view。

View;

importandroid.view。

View。

OnClickListener;

importandroid.widget.Button;

importandroid。

widget。

EditText;

importandroid。

widget。

TextView;

importandroid.widget.Toast;

publicclassMainActivityextendsActionBarActivityimplementsOnClickListener

privateintsaveCountor;

privateintsaveCountorImage;

privateFilefile;

privateEditTextet_content;

privateButtonbt_back;

privateTextViewtv_details;

protectedvoidonCreate(BundlesavedInstanceState)

inti=1;

super.onCreate(savedInstanceState);

setContentView(R。

layout。

activity_main);

btSet();

do

{

Stringstr=”content”+i;

file=newFile(this.getFilesDir(),str);

i++;

}

while(file.exists());

saveCountor=i-1;

contentFindSet();

saveCountorImage=saveCountor;

}

privatevoidcontentFindSet()

TextViewnote_save1=(TextView)this。

findViewById(R.id.note_saved1);

TextViewnote_save2=(TextView)this。

findViewById(R.id。

note_saved2);

TextViewnote_save3=(TextView)this.findViewById(R。

id。

note_saved3);

TextViewnote_save4=(TextView)this。

findViewById(R。

id。

note_saved4);

TextViewnote_save5=(TextView)this。

findViewById(R.id。

note_saved5);

if(saveCountor〈5)

{

note_save1.setText("NoSaved");

note_save2。

setText(”");

note_save3。

setText(””);

note_save4.setText("");

note_save5.setText("”);

else

{

note_save1。

setText((CharSequence)noteService。

getSavedContent(

MainActivity.this,saveCountor—1));

note_save2.setText((CharSequence)noteService.getSavedContent(

MainActivity。

this,saveCountor—2));

note_save3.setText((CharSequence)noteService.getSavedContent(

MainActivity。

this,saveCountor-3));

note_save4。

setText((CharSequence)noteService.getSavedContent(

MainActivity.this,saveCountor-4));

note_save5。

setText((CharSequence)noteService。

getSavedContent(

MainActivity.this,saveCountor-5));

}

}

privatevoidcontentFindSet(intsaveCountor)

{

TextViewnote_save1=(TextView)this。

findViewById(R。

id.note_saved1);

TextViewnote_save2=

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2