昨天所做:显示SQLite中内容到主页面
代码是冲刺完才粘的,可能会和所说的有所不同
//显示账单 public List<BillBean> showBill(List<BillBean> billlist) { Cursor cursor = mDB.query(TABLE_NAME,null,null,null,null,null,null); cursor.moveToLast(); if(cursor != null && cursor.getCount() > 0) { do { BillBean billBeanshow = new BillBean(cursor.getInt(0), cursor.getDouble(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5)); billlist.add(billBeanshow); } while (cursor.moveToPrevious()); } cursor.close(); return billlist; }
package com.example.accountbook; import android.content.Context; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import java.util.List; public class BillAdapter extends ArrayAdapter<BillBean> { private int resourceId; public BillAdapter(Context context, int textViewResourceId, List<BillBean> objucts) { super(context,textViewResourceId,objucts); resourceId = textViewResourceId; } public View getView(int position, View convertView, ViewGroup parent) { BillBean billBean = getItem(position); View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false); TextView tv_money = view.findViewById(R.id.tv_money); TextView tv_sort = view.findViewById(R.id.tv_sort); TextView tv_time = view.findViewById(R.id.tv_time); //整型 double mo = billBean.getMoney(); int mon = (int) mo; tv_money.setText(String.valueOf(mon)); tv_sort.setText(billBean.getSort()); tv_time.setText(billBean.getTime()); //money颜色 String c = billBean.getChoose(); if(c.equals("支出")) { tv_money.setTextColor(Color.parseColor("#da0101")); }else if(c.equals("收入")) { tv_money.setTextColor(Color.parseColor("#18cb00")); } return view; } }
今天将做:实现主页面ListView连接SQLite的长按删除操作
遇到问题:— —