If you have to load info from a db, maybe it helps you to do a basic XML, and insert info on it, like a table or something like that. You can try something like this:
In a basic table XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas./apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:id="@+id/SensorInfoTableLayout">
<TableRow>
<TextView
android:text="@string/sensor_name_title"
android:padding="3dip" />
<TextView
android:text="@string/sensor_type_title"
android:padding="3dip" />
<TextView
android:text="@string/sensor_value_title"
android:padding="3dip" />
<TextView
android:text="@string/sensor_unit_title"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="4dip"
android:background="#FF909090" /></TableLayout>
And the code:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getSensorInfo();
setContentView(R.layout.sensorinfo);
setInfoByView();
}
private void setInfoByView()
{
TableLayout myTableLayout = null;
myTableLayout = (TableLayout)findViewById(R.id.SensorInfoTableLayout);
// Add row to table
myTableLayout.addView(createRow("maxRange",maxRangeType, "" + maxRange ,maxRangeUnits));
myTableLayout.addView(createRow("minDelay",minDelayType,"" + minDelay, minDelayUnits));
myTableLayout.addView(createRow("name",nameType,"" + name, nameUnits));
myTableLayout.addView(createRow("powerReq",powerReqType,"" + powerReq, powerReqUnits));
myTableLayout.addView(createRow("resolution",resolutionType,"" + resolution, resolutionUnits));
myTableLayout.addView(createRow("type",typeType,"" + type, typeUnits));
myTableLayout.addView(createRow("vendor",vendorType,"" + vendor, vendorUnits));
myTableLayout.addView(createRow("version",versionType,"" + version, versionUnits));
}
private TableRow createRow(String name, String type, String value, String unit)
{
// Create new row
TableRow myTableRow = new TableRow(this);
myTableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
//myTableRow.setGravity(Gravity.CENTER_HORIZONTAL);
myTableRow.setPadding(5, 5, 5, 5);
// Add name
myTableRow.addView(createTextView(name));
// Add type
myTableRow.addView(createTextView(type));
// Add value
myTableRow.addView(createTextView(value));
// Add units
myTableRow.addView(createTextView(unit));
return myTableRow;
}
In the XML, it only exists the principal bar, with name, title, value and unit. And dinamically, add rows with info and style.
Maybe it helps, it works for me.