I have read various posts on programmatically creating a TableLayout
/ListView
and I'm still unsure of the best route to take.
In my mind I have one class called RunTests.java
. One test schedule can contain numerous test types, and for each test type a table of results is required. So let's say there are four tests, named A, B, C and D.
After test A has completed I'd ideally like to call another class (ProcessTable.java
) and pass it an array of test results, and array of test column headings and an array of test row headings. The class would then return a table, complete with results and headings, and inflate it so it becomes visible within an XML LinearLayout
, and then move on to test B.
The process would then repeat and the next table would appear below the first one, and so on.
Any advice or examples would be great.
Thanks
Attempt at suggested answer:
I'm getting an error on listView, I'm not sure where I define this. The XML I've added to be existing layout is below:
private void createTable() {
String[] columns = {"row_header", "column_name1", "column_name2"};
String[] results = {"","2000","98"};
int[] to = { R.id.row_header, R.id.txt1 ,R.id.txt2};
String[] rowHeadings = {"","Bandwidth","QoS"};
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
for(int i = 0; i < rowHeadings.length; i++){
HashMap<String, String> map = new HashMap<String, String>();
map.put(columns[0], rowHeadings[i].toString());
map.put(columns[1], results[1]);
map.put(columns[2], results[2]);
data .add(map);
}
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), data, R.layout.runtests, columns, to);
listView.setAdapter(adapter);
}
XML:
<LinearLayout android:id="@+id/resultsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:background="@drawable/curvedbg"
android:layout_marginTop="10dp"
android:padding="5dp"
android:weightSum="99">
<TextView android:id="@+id/row_header" android:layout_weight="33" />
<TextView android:id="@+id/txt1" android:layout_weight="33"/>
<TextView android:id="@+id/txt2" android:layout_weight="33"/>
</LinearLayout>