Reputation: 1902
I want to set all the rows of a database in a listview so that i may click on that particular item to see that details in a full screen on next activity.
I am able to set all the rows in a textview but now I want to set it in a listview so that it may look better.
I searched regarding this and I got this but I feel this code is used in a lengthy way. They took a class contact.java that I haven't and i feel that there's no requirement of that class. So if there is requirement than I may implement that code.
Is there any easier and smaller way to do this?
The code I used for setting it in a TextView is:
String data = odb.getData();
odb.close();
tv.setText(data);
public String getData() {
// TODO Auto-generated method stub
String[] columns = new String[] { KEY_ROWID, KEY_DATE, KEY_WHOM,
KEY_PRICE, KEY_ITEM, KEY_AMOUNT };
Cursor c = ourdatabase.query(DATABASE_TABLE, columns, null, null, null,
null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iDate = c.getColumnIndex(KEY_DATE);
int iWhom = c.getColumnIndex(KEY_WHOM);
int iPrice = c.getColumnIndex(KEY_PRICE);
int iItem = c.getColumnIndex(KEY_ITEM);
int iAmount = c.getColumnIndex(KEY_AMOUNT);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result + c.getString(iRow) + " " + c.getString(iDate)
+ " " + c.getString(iWhom) + c.getString(iPrice) + " "
+ c.getString(iItem) + " " + c.getString(iAmount) + "\n";
}
return result;
}
Upvotes: 0
Views: 38
Reputation: 1932
There is tutorial on the Android developer site called "Notepad Tutorial". Go it has similas functionality to what you are trying to achieve. Here is the link to it:
http://developer.android.com/training/notepad/index.html
Upvotes: 1