Combining this with my response from above, you could order by the id, then use a value in Java that you increment inside your getAllNames() method which you present to the user. There is basic SQL syntax for doing this, so I will leave you to investigate it. You need to order your elements when you are querying for them. Databases and database queries are generally un-order collections of things - there is no 'sit sequentially'. Or the newly added item should sit sequentially in the database. The user should be unaware of how the database increments or maintains its identifiers. I actually think the unique ids in the database should be independent of anything you display to the user. I am not positive this is the best route to go though. String Name=res.getString(res.getColumnIndex(CONTACTS_COLUMN_NAME)) ĭinnu goud wrote:What I am expecting is ,whenever an item is deleted or all the items are deleted either the column ids should get updated If you want to renumber the ids in the database, then you need to renumber the ids - your delete code would have to be extended to get all items with a greater id and decrement them. String Index=res.getString(res.getColumnIndex(CONTACTS_COLUMN_ID)) SQLiteDatabase db = this.getReadableDatabase() Ĭursor res = db.rawQuery( "select * from nameBook", null ) įor(res.moveToFirst() !res.isAfterLast() res.moveToNext()) Intent intent = new Intent(getApplicationContext().class) Obj.setOnItemClickListener(new void onItemClick(AdapterView arg0, View arg1, int pos, long arg3) Obj = (ListView)findViewById(R.id.listView1) ![]() ![]() My problem is when I delete these items and add a new one ,list showsĨ.item name(in place of 1.item name) even though there are no elements in it.Which is not appropriate from user's perspective.What I am expecting is ,whenever an item is deleted or all the items are deleted either the column ids should get updated or the newly added item should sit sequentially in the database.įinal ArrayList array_list = mydb.getAllNames() įinal ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list) Hi,I have an arraylist in my android app where I can see list of names like:ġ,2,3,4,5,6,7 are coloumn ids in my sqlite database.Column id is set to primary key with auto increment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |