I’m a beginner in Android..Could you please tell me
-
How can we get selected list item’s primary_key_id from SQLite table..(if possible please give me an example).
-
How can we avoid redundant entries in a string Array?
Thanks in advance..
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Question 2 is easy: if you’re using a String[], you have to look through the entire array to check for redundant entries. If you want an object that doesn’t allow you to insert a redundant entry, look at the classes in java.util.*. Start with HashMap.
Question 2 is much harder. I don’t know how you’re creating the SQLite table. An SQLite table has a default “primary key” column with the aliases ROWID, ROWID, or OID. Each row in the table has a unique value of this key.
If you haven’t used the PRIMARY KEY construct in creating your table, then those aliases are what you use to refer to the column.
If you specify a column with a column name and INTEGER PRIMARY KEY, then you can use that column name to access the primary key, as well as the other aliases.
For SQLite tables that back a ListView, you should use
CREATE TABLE People (
_id INTEGER PRIMARY KEY,
…
Note the column name. To work properly, a ListAdapter needs a Cursor that includes _id as one of the column names. You don’t have to use _id in the View, but it has to be in the Cursor. It’s often useful to have, because when a user clicks an entry in the ListView you can find the corresponding Cursor row and get its data.
The value of _id is usually not important. If you want to know all the details of how SQLite assigns it, they’re described on this page.