【团队】 冲刺一(8/10)

本文详细介绍了如何在Android应用中使用SQLite数据库存储账单信息,并通过ListView组件展示这些数据。文章分享了具体的代码实现,包括从SQLite读取数据并填充到ListView的方法,以及如何根据账单类型设置文字颜色。此外,还提到了计划实现的主页面长按删除操作。

昨天所做:显示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的长按删除操作

遇到问题:— —

 

转载于:https://www.cnblogs.com/gothic-death/p/10933380.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值