0
我正在編寫我的第一個重要的android應用程序,並且需要一些幫助將貨幣格式應用於listView中的某些textView。我想將CURRENT_VALUE和TOTAL_VALUE字段格式設置爲貨幣。我已經做了一些關於ViewBinde的閱讀,我猜想它是我需要使用的,但似乎無法繞過它與我已經獲得的代碼之間的關係。任何幫助,將不勝感激。需要幫助將listView中的項目格式化爲貨幣
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;
}
}
更簡單,比我走的路線直接。謝謝 –
不客氣。由於您是新手,您可能需要查看此[鏈接](http://meta.stackexchange.com/a/5235/187716)。 – Barak