万书网 > 文学作品 > Android从入门到精通 > 第183页

第183页


}



});

15.11.4 设计便签信息浏览布局文件

便签信息浏览窗体运行效果如图15.16所示。



图15.16 便签信息浏览

说明:  便签信息浏览功能是在数据管理窗体中实现的,该窗体的布局文件是showinfo.xml,对应的java文件是Showinfo.java,所以下面讲解时,会通过对showinfo.xml布局文件和Showinfo.java文件的讲解,来介绍便签信息浏览功能的实现过程。

在res\layout目录下新建一个showinfo.xml文件,用来作为数据管理窗体的布局文件,该布局文件中可以浏览支出信息、收入信息和便签信息。showinfo.xml布局文件使用LinearLayout结合RelativeLayout进行布局,在该布局文件中添加3个Button组件和一个ListView组件,代码如下:








android:id="@+id/iteminfo"  android:orientation="vertical"



android:layout_width="wrap_content"  android:layout_height="wrap_content"



android:layout_marginTop="5dp"



android:weightSum="1">






android:layout_height="wrap_content"



android:layout_width="match_parent"



android:orientation="vertical"



android:layout_weight="0.06">






android:layout_width="match_parent">






android:id="@+id/btnoutinfo"



android:layout_width="wrap_content"



android:layout_height="wrap_content"



android:textSize="20dp"



android:textColor="#8C6931"



/>






android:id="@+id/btnininfo"



android:layout_width="wrap_content"



android:layout_height="wrap_content"



android:layout_toRightOf="@id/btnoutinfo"



android:textSize="20dp"



android:textColor="#8C6931"



/>






android:id="@+id/btnflaginfo"



android:layout_width="wrap_content"



android:layout_height="wrap_content"



android:layout_toRightOf="@id/btnininfo"



android:textSize="20dp"



android:textColor="#8C6931"



/>














android:layout_height="wrap_content"



android:layout_width="match_parent"



android:orientation="vertical"



android:layout_weight="0.94">






android:layout_width="match_parent"



android:layout_height="match_parent"



android:scrollbarAlwaysDrawVerticalTrack="true"



/>









15.11.5 显示所有的便签信息

在com.xiaoke.accountsoft.activity包中创建一个Showinfo.java文件,该文件的布局文件设置为showinfo.xml。单击“便签信息”按钮,为该按钮设置监听事件,在监听事件中,调用ShowInfo()方法显示便签信息,代码如下:

btnflaginfo.setOnClickListener(new  OnClickListener()  {  //为“便签信息”按钮设置监听事件



@Override



public  void  onClick(View  arg0)  {



//TODO  Auto-generated  method  stub



ShowInfo(R.id.btnflaginfo);  //显示便签信息



}



});

上面的代码中用到了ShowInfo()方法,该方法为自定义的无返回值类型方法,主要用来根据传入的管理类型显示相应的信息,该方法中有一个int类型的参数,用来表示传入的管理类型,该参数的取值主要有R.id.btnoutinfo、R.id.btnininfo和R.id.btnflaginfo  3个,分别用来显示支出信息、收入信息和便签信息。ShowInfo()方法的代码如下:

private  void  ShowInfo(int  intType)  {  //用来根据传入的管理类型显示相应的信息



String[]  strInfos  =  null;  //定义字符串数组,用来存储收入信息



ArrayAdapter  arrayAdapter  =  null;  //创建ArrayAdapter对象



switch  (intType)  {  //以intType为条件进行判断



case  R.id.btnoutinfo:  //如果是btnoutinfo按钮



strType="btnoutinfo";  //为strType变量赋值



OutaccountDAO  outaccountinfo=new  OutaccountDAO(Showinfo.this);