Android Open Source - Xpense Cash Flow List Adapter






From Project

Back to project page Xpense.

License

The source code is released under:

MIT License

If you think the Android project Xpense listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kevinzhu.xpense;
// ww w. j ava2  s  .  c  o m
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by kevin on 12/29/14.
 */
public class CashFlowListAdapter extends BaseAdapter{

    private Context c;
    private List<CashFlow> data;

    public CashFlowListAdapter(Context c, List<CashFlow> data) {
        this.c = c;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DecimalFormat df = new DecimalFormat("#.00");
        LayoutInflater inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null){
            convertView = inflater.inflate(R.layout.cashflow_list_element, null);
        }
        TextView category = (TextView)convertView.findViewById(R.id.category);
        TextView subcategory = (TextView)convertView.findViewById(R.id.subcategory);
        TextView amount = (TextView)convertView.findViewById(R.id.amount);
        TextView date = (TextView)convertView.findViewById(R.id.date);
        TextView comments = (TextView)convertView.findViewById(R.id.comments);

        CashFlow cashFlowElement = data.get(position);
        String type = cashFlowElement.getM_type();
        category.setText(cashFlowElement.getM_category());
        subcategory.setText(cashFlowElement.getM_subcategory());
        amount.setText("$" + df.format(cashFlowElement.getM_amount()));
        String commentString = cashFlowElement.getM_comments();
        if (!commentString.equals("")) {
            comments.setText("\"" + cashFlowElement.getM_comments() + "\"");
        }
        else{
            comments.setText("\"No comment\"");
        }
        comments.setTypeface(null, Typeface.ITALIC);

        if (type.equals("Income")){
            amount.setTextColor(c.getResources().getColor(R.color.income_green));
        }
        else{
            amount.setTextColor(c.getResources().getColor(R.color.expense_red));
        }
        date.setText(""+cashFlowElement.getM_payDate());

        return convertView;
    }
}




Java Source Code List

com.kevinzhu.xpense.ApplicationTest.java
com.kevinzhu.xpense.CashFlowListAdapter.java
com.kevinzhu.xpense.CashFlow.java
com.kevinzhu.xpense.CashList.java
com.kevinzhu.xpense.DatePickerFragment.java
com.kevinzhu.xpense.Main.java
com.kevinzhu.xpense.NewEntry.java
com.kevinzhu.xpense.SwipeDismissListViewTouchListener.java
com.kevinzhu.xpense.Xpense.java