I have read so many posts about how to populate the listview from the database but I just can not do it on my app ! I do not know what is doing wrong. I am very new to programming, so I am not allocating things that I do not understand, but I am trying to learn :)
I add the item to the database without any problem in using this code in the activity:
string selected stone = (string) stonespinner.getSelectedItem (); String weight = atadvite.gate text (). ToString (); Db.addStone (new MyStonesDatabase (selected stone, weight)); I have this:
// Add new Stone Zero Adstone (MyStones database database) {SQLiteDatabase db = this.getWritableDatabase (. ); Material values = new material value (); Values.put (KEY_STONE, stone.getStone ()); Values.put (KEY_WEIGHT, stone.getWeight ()); // enter the line DB.inet (TABLE_MYSTONES, zero, value); Db.close (); // database connection termination} I can see that my database is populated by running:
log. D. ("Reading:", "Reading All Items .."); & Lt; MyStonesDatabase & gt; Item = db.getAllstones (); (Mattsonsdatabase.cn: item) {string log = "id:" + cn.getID () + ", stone:" + cn.getStone () + ", weight:" + cn.getWeight (); To log the log // write the article ("name:", log); } But when trying to keep a list view to show the database, my app crashes or does not show anything. Handler in my database. I have this in Java:
// Obtaining all items from the database Public list & lt; MyStonesDatabase & gt; GetAllstones () {List & lt; MyStonesDatabase & gt; Stone List = New Arrestist & lt; MySpace Database & gt; (); // Choose all the query string selectQuery = "SELECT * FROM" + TABLE_MYSTONES; SQLiteDatabase db = this.getWritableDatabase (); Cursor cursor = db.rawQuery (selectQuery, zero); // Adding looping and list through all the rows if (cursor.movatofst ()) {to {MyStonesDatabase stone = new MyStonesDatabase (); Stone.setID (Integer.parseInt (cursor.getString (0)); Stone.setStone (cursor.getString (1)); Stone.setWeight (cursor.getString (2)); // stone stone link add stone (stone); } While (cursor.movetoonext ()); } // Return Stoneworth return stone; } I do not know what should be included in my activity, which should show list view.
Public class increases the list of MySTONS inventory {/ ** is called when activity first created * / @Override Public Zero OnCreate (bundled savedInstanceState) {super.onCreate (savedInstanceState); } }
Can someone please help me, please leave it to Hehe :) Thanks!
Here's a great article / tutorial that can help you. Viewing your list view is not as easy to do in your activity. You need to create a list of adapters and other things in tutorials, they use hard-coded values in an array. You can try to work it out, then remove the data with the hard code, and you can use the data from your DB.
This work is a little easier than you think, but is not too complicated.
Hope this helps:
Comments
Post a Comment