package com.xiaoke.accountsoft.activity;import java.util.List;import com.xiaoke.accountsoft.dao.InaccountDAO;import com.xiaoke.accountsoft.model.Tb_inaccount;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.TextView;import android.widget.AdapterView.OnItemClickListener;public class Inaccountinfo extends Activity {public static final String FLAG = "id";// 定义一个常量,用来作为请求码ListView lvinfo;// 创建ListView对象String strType = "";// 创建字符串,记录管理类型@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.inaccountinfo);// 设置布局文件lvinfo = (ListView) findViewById(R.id.lvinaccountinfo);// 获取布局文件中的ListView组件ShowInfo(R.id.btnininfo);// 调用自定义方法显示收入信息lvinfo.setOnItemClickListener(new OnItemClickListener()// 为ListView添加项单击事件{// 覆写onItemClick方法@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {String strInfo = String.valueOf(((TextView) view).getText());// 记录收入信息String strid = strInfo.substring(0, strInfo.indexOf('|'));// 从收入信息中截取收入编号Intent intent = new Intent(Inaccountinfo.this, InfoManage.class);// 创建Intent对象intent.putExtra(FLAG, new String[] { strid, strType });// 设置传递数据startActivity(intent);// 执行Intent操作}});}///onCreateprivate void ShowInfo(int intType) {// 用来根据传入的管理类型,显示相应的信息String[] strInfos = null;// 定义字符串数组,用来存储收入信息ArrayAdapter<String> arrayAdapter = null;// 创建ArrayAdapter对象strType = "btnininfo";// 为strType变量赋值InaccountDAO inaccountinfo = new InaccountDAO(Inaccountinfo.this);// 创建InaccountDAO对象// 获取所有收入信息,并存储到List泛型集合中List<Tb_inaccount> listinfos = inaccountinfo.getScrollData(0,(int) inaccountinfo.getCount());strInfos = new String[listinfos.size()];// 设置字符串数组的长度int m = 0;// 定义一个开始标识for (Tb_inaccount tb_inaccount : listinfos) {// 遍历List泛型集合// 将收入相关信息组合成一个字符串,存储到字符串数组的相应位置strInfos[m] = tb_inaccount.get_id() + "|" + tb_inaccount.getType()+ " " + String.valueOf(tb_inaccount.getMoney()) + "元     "+ tb_inaccount.getTime();m++;// 标识加1}// 使用字符串数组初始化ArrayAdapter对象arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, strInfos);lvinfo.setAdapter(arrayAdapter);// 为ListView列表设置数据源}@Overrideprotected void onRestart() {// TODO Auto-generated method stubsuper.onRestart();// 实现基类中的方法ShowInfo(R.id.btnininfo);// 显示收入信息}}

更多相关文章

  1. Android资源文件 - 使用资源存储字符串 颜色 尺寸 整型 布尔值
  2. Android(安卓)Kotlin ListView的使用
  3. android之调用webservice 实现图片上传下载
  4. Android震动---启动、循环、取消控制
  5. Android中String资源文件的format方法
  6. Qt for Android(安卓)调用android原生接口分享图片或文字
  7. Pro Android(安卓)4 第三章 理解Android中的资源
  8. 官方NotePad实例学习--ListActivity的使用
  9. Android(安卓)基础——第一行代码读书笔记(1)

随机推荐

  1. android设置图片变化的四种效果代码
  2. To make the android emulator (AVD) wor
  3. Android(安卓)创建与解析XML(五)—— Dom4j
  4. android -- 小功能 Android为多媒体文件
  5. android 把view转成bitmap~~~
  6. MSDK接入 中的各种问题
  7. Android(安卓)仿360桌面小人
  8. Android(安卓)Activity淡入淡出动画
  9. 短信拦截的解决方案 经典
  10. android SQLiteOpenHelper 对SQLite的操