In my application i am displaying the database in a ListView. In that i have 2 columns. I will retrieve data from database and display in the ListView. My problem is in database after displaying 1st entry it should got to next line and print the next entry, but it is not like that, it is going in column wise. Please help me.
My code is as follows:
ListView lv=(ListView)findViewById(R.id.listView1);
db.open();
Cursor c = db.getAllTitles();
startManagingCursor(c);
System.out.println("cursor="+c.getCount());
String[] from = new String[] { db.KEY_INCOME,db.KEY_INCOME};
int[] to = new int[] {R.id.text1 ,R.id.text2,R.id.text3};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.columnview, c, from, to);
// System.out.println("notes="+notes.getCount());
// setListAdapter(notes);
lv.setAdapter(notes);
System.out.println("subbu");
// System.out.print("tot="+db.add().toString());
String sumtotal= db.add();
My main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false" >
</ListView>
</LinearLayout>
My column.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/text1"
android:textSize="18sp"
android:layout_width="30dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/text2"
android:textSize="18sp"
android:layout_width="110dip"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_weight="1"/>
<TextView android:id="@+id/text3"
android:textSize="18sp"
android:layout_width="30dip"
android:layout_height="wrap_content"/>
</LinearLayout>
Problem:
The problem is that you have given two columns of db and three
TextViewof. hereSolution:
Add another column or remove any
TextView‘s id fromint[] to, that means the length ofString[] fromandint[] toshould be identical.