Need help formatting items in a listView as currency

I am writing my first significant android app and need some help applying a currency format to some textViews in a listView. I want to format CURRENT_VALUE and TOTAL_VALUE fields as currency. I've done some reading about ViewBinde, which I suspect is what I need to use, but can't seem to wrap my head around the relationship between it and the code I've already got. Any help would be appreciated.

    private void fillData() {

    DBAdapter db = new DBAdapter(this);
        db.open();
    Cursor c = db.getAllInventory();
        startManagingCursor(c);

        String[] from = new String[] { db.DESCRIPTION ,db.QUANTITY,db.CURRENT_VALUE, db.TOTAL_VALUE};
        int[] to = new int[] { R.id.text1,R.id.text2,R.id.text3,R.id.text4 };


        SpecialCursorAdapter invItems =
            new SpecialCursorAdapter(this, R.layout.inv_item, c, from,to);
        setListAdapter(invItems);
    }


public class SpecialCursorAdapter extends SimpleCursorAdapter 

{
    private int[] colors = new int[] { 0xFFD0D1D2, 0xFFFFFFFF };

    public SpecialCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
    {
        super(context,layout, c, from, to);




    }
   @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = super.getView(position, convertView, parent);
      int colorPos = position % colors.length;
      view.setBackgroundColor(colors[colorPos]);
      return view;

    }

}

Answers


I do it using the DecimalFormat class in my getView method, like this:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null)
        convertView = View.inflate(context, layout, null);
    View row = convertView;
    c.moveToPosition(position);

    TextView fourth = (TextView) convertView.findViewById(R.id.ListItem4);

    DecimalFormat df = new DecimalFormat("0.00");
    Double total = Double.valueOf(c.getString(3));

    fourth.setText("$" + df.format(total));
    fourth.setTextColor(MyApplication.shoplistitem_desc);

    return row;
}

Need Your Help

How to handle TIdHTTPServer with TIdMultiPartFormDataStream

delphi indy indy10 simplehttpserver

Hi i need help on how to retrieved the parameters and data using IdHttpServer from indy.