I am trying to display some items in a listview, which is located in a relativelayout. The whole layout is located in one xml file (main.xml)
The layout has also 2 buttons and 2 more textfields (EditText).
I can`t get it to work, as:
The listview does not show the items
If the listview expands, it duplicates the buttons and textfields present in the layout
can someone please help me?
Here is a part of the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/kpnback">
<EditText
android:layout_height="wrap_content"
android:layout_width="110dp"
android:id="@+id/editText1"
android:text="edit1"
android:inputType="textMultiLine"
android:layout_below="@+id/lbl_top">
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_width="110dp"
android:id="@+id/editText2"
android:text="edit2"
android:inputType="textMultiLine"
android:layout_marginLeft="160dp"
android:layout_below="@+id/lbl_top">
</EditText>
<ListView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:id="@+id/kpn"
android:layout_y="350dp"
android:layout_below="@+id/editText1">
</ListView>
</RelativeLayout>
Code for the simpleadapter:
@Override
protected void onPostExecute(String result) {
// create the grid item mapping
ListView kp = (ListView)findViewById(R.id.kpn);
String[] from = new String[] {"col_1", "col_2"};
int[] to = new int[] { R.id.editText1, R.id.editText1 };
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
Document doc = Jsoup.parse(kpn);
Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)");
for (Element tdFromSecondColumn : tdsFromSecondColumn) {
map.put("col_1", tdFromSecondColumn.text());
fillMaps.add(map);
System.out.println(tdFromSecondColumn.text());
}
for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
map.put("col_2", tdFromSecondColumn1.text());
fillMaps.add(map);
System.out.println(tdFromSecondColumn1.text());
}
SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fillMaps, R.layout.main, from, to);
kp.setAdapter(adapter);
1) Do not use "@+id/..." for the layout_below attribute.. Instead use "@id/..."
2) lbl_top is not present inside the RelativeLayout..
3) You'll have to specify layout_toLeftOf or layout_toRightOf, apart from specifying layout_below.
Hope this helps..