txtInMoney.setText(""); //设置“金额”文本框为空
txtInMoney.setHint("0.00"); //为“金额”文本框设置提示
txtInTime.setText(""); //设置“时间”文本框为空
txtInTime.setHint("2011-01-01"); //为“时间”文本框设置提示
txtInHandler.setText(""); //设置“付款方”文本框为空
txtInMark.setText(""); //设置“备注”文本框为空
spInType.setSelection(0); //设置“类别”下拉列表默认选择第一项
}
});
15.10.5 设计收入信息浏览布局文件
收入信息浏览窗体运行效果如图15.13所示。
图15.13 收入信息浏览
在res\layout目录下新建一个inaccountinfo.xml文件,用来作为收入信息浏览窗体的布局文件,该布局文件使用LinearLayout结合RelativeLayout进行布局,在该布局文件中添加一个TextView组件和一个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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
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.10.6 显示所有的收入信息
在com.xiaoke.accountsoft.activity包中创建一个Inaccountinfo.java文件,该文件的布局文件设置为inaccountinfo.xml。在Inaccountinfo.java文件中,首先创建类中需要用到的全局对象及变量,代码如下:
public static final String FLAG = "id"; //定义一个常量,用来作为请求码
ListView lvinfo; //创建ListView对象
String strType = ""; //创建字符串,记录管理类型
在onCreate()覆写方法中,初始化创建的ListView对象,并显示所有的收入信息,代码如下:
lvinfo=(ListView) findViewById(R.id.lvinaccountinfo); //获取布局文件中的ListView组件
ShowInfo(R.id.btnininfo); //调用自定义方法显示收入信息
上面的代码中用到了ShowInfo()方法,该方法用来根据参数中传入的管理类型id,显示相应的信息,代码如下:
private void ShowInfo(int intType) { //用来根据管理类型显示相应的信息
String[] strInfos = null; //定义字符串数组,用来存储收入信息
ArrayAdapter
strType="btnininfo"; //为strType变量赋值
InaccountDAO inaccountinfo=new InaccountDAO(Inaccountinfo.this);//创建InaccountDAO对象
//获取所有收入信息,并存储到List泛型集合中
List
strInfos=new String[listinfos.size()]; //设置字符串数组的长度
int m=0; //定义一个开始标识
for (Tb_inaccount tb_inaccount:listinfos) { //遍历List泛型集合
//将收入相关信息组合成一个字符串,存储到字符串数组的相应位置
strInfos[m]=tb_inaccount.getid()+"|"+tb_inaccount.getType()+" "+String.valueOf(tb_inaccount.getMoney())+ "元 "+tb_inaccount.getTime();