Код: Выделить всё
private void adapter() {
Calculation calculation = new Calculation(margin, cost);
calculation.calc();
// упаковываем данные в понятную для адаптера структуру
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(
100);
Map<String, Object> m;
for (int i = 0; i < 100; i++) {
m = new HashMap<String, Object>();
m.put(ATTRIBUTE_NAME_DISCOUNT, calculation.ar_discount[i]);
m.put(ATTRIBUTE_NAME_COSTDISCOUNT, calculation.ar_costDiscount[i]);
m.put(ATTRIBUTE_NAME_INCOME, calculation.ar_income[i]);
data.add(m);
}
// массив имен атрибутов, из которых будут читаться данные
String[] from = { ATTRIBUTE_NAME_DISCOUNT, ATTRIBUTE_NAME_COSTDISCOUNT,
ATTRIBUTE_NAME_INCOME };
// массив ID View-компонентов, в которые будут вставлять данные
int[] to = { R.id.tv_discount, R.id.tv_costDiscount, R.id.tv_income };
// создаем адаптер
SimpleAdapter sAdapter = new SimpleAdapter(this, data, R.layout.item,
from, to);
// списку присваиваем адаптер
lv_result.setAdapter(sAdapter);
}
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lL_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_discount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp" >
</TextView>
<TextView
android:id="@+id/tv_costDiscount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp" >
</TextView>
<TextView
android:id="@+id/tv_income"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp" >
</TextView>
</LinearLayout>
Спасибо.