I have collection of HashMap<String,Object>
data as ArrayList
.
I used following method to add HashMap
data to ArrayList
.
mylist = new ArrayList<HashMap<String, Object>>();
for (Data dt : data) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", dt.getWeekNo());
map.put("description", dt.getDesc());
map.put("Amount", dt.getAmount());
mylist.add(map);
}
Data
is a separate class which is used to Getters
and Setters
purpose only.
Now my output is like:
3 | Income | 1000
5 | Income | 1500
3 | Expense | 250
5 | Expense | 500
I want it as the following to my listview.
3 | Income : 1000 | Expense : 250
5 | Income : 1500 | Expense : 500
Any idea to achieve this. I dont know how to achieve and I dont know any idea too so I dont know where to start.
Updates :
This is the way I am adapt my list to listview with getview()
method
ListAdapter adapter
= new SimpleAdapter(this, mylist, R.layout.txnlist,
new String[] {"id", "description", "Amount" },
new int[] { R.id.txntext1, R.id.txntext2, R.id.txntext3 }) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.txnlist, null);
}
Collection<Object> str = mylist.get(position).values();
ArrayList<Object> al1 = new ArrayList<Object>(str);
TextView amnt = (TextView) v.findViewById(R.id.txntext3);
if (al1.get(2).toString().equals("Income"))
amnt.setTextColor(Color.GREEN);
if (al1.get(2).toString().equals("Expense"))
amnt.setTextColor(Color.RED);
return super.getView(position, v, parent);
}
};
ListView lv1 = (ListView) findViewById(R.id.repListView);
Help me friends.
Thanks in advance.