java - How to show IDs of objects in ArrayList -
i have little application can write random stuff , save in sqllite database file. activity read informations , show in arraylist. created button delete first object of list. i'm trying alter bit user can take object deleted. , it's working great well. problem don't know how show ids of objects list on screen. can @ code , help me?
oncreate in activity shows list:
dbwrapper = new mydatabasewrapper(this); dbwrapper.open(); mycontactslist = dbwrapper.getallcontacts(); this.setlistadapter(new arrayadapter<mycontact>(this, android.r.layout.simple_list_item_1, mycontactslist));
getallcontacts function mydatabasewrapper:
public list<mycontact> getallcontacts() { list<mycontact> mylist = new arraylist<mycontact>(); cursor c = db.rawquery("select * " + contacts_table, null); c.movetofirst(); while (!c.isafterlast()) { mycontact mc = new mycontact(); mc.setdata(c.getint(0), c.getstring(1), c.getstring(2), c.getstring(3)); c.movetonext(); mylist.add(mc); } c.close(); homecoming mylist; }
and class convert values database string:
package com.example.sqlite; import java.util.arraylist; import java.util.list; public class mycontact { string imie; string nazwisko; string tel; int id; public mycontact() { // todo auto-generated constructor stub } public void setdata(int _id, string i, string n, string t){ id=_id; imie=i; nazwisko=n; tel=t; } @override public string tostring() { homecoming "[" + string.valueof(id) + "]" + "\n" + imie + "\n" + nazwisko + "\n" + tel; } public int getid() { homecoming id; } }
it looks that: http://screenshooter.net/100009676/chxmipm http://screenshooter.net/100009676/ngbxmgx
i deleted 1 object number 3.
so yeah. far number in "[ ]" id database. want alter number id of object.
i don't much android dev apologize may not understand this, why can't utilize indexof(object o)
? wouldn't plenty id of given element, long know element itself? (which, assuming want delete it, would)
java android arraylist
No comments:
Post a Comment