android-sqlite

Displaying data in a RecyclerView

房东的猫 提交于 2019-12-13 10:56:02
问题 I have this working perfectly with a ListView, but decided to update my code to use RecyclerView. I see there is no default implementation, and the responses to similar questions are quite old. Is using a sort of cursor the best way to go, or is there a better option? These are my code snippets for a working RecyclerView with hard-coded values: MainActivity recyclerView = (RecyclerView)findViewById(R.id.recycler_view); mLayoutmanager = new LinearLayoutManager(this); recyclerView

Storing image resource id in Sqlite database and retrieving it in int array

江枫思渺然 提交于 2019-12-13 10:53:56
问题 I am developing an online shopping app, where I am storing all the product details in Sqlite database, along with resource ids of product images. I am retrieving those ids(eg: R.drawable.image1), in order to display the images, stored in drawable folder. The ids are retrieved precisely, but an exception occurs, as "InvalidNumberFormatException: R.drawable.image1". I have stored all the ids, as VARCHAR, in sqlite. How can I store these ids in an int array, after they are retrieved as string

How to read and update SQLite database using ListView in Android?

牧云@^-^@ 提交于 2019-12-13 10:44:20
问题 I've been doing research in the internet for 15-20 hours and can't find the answer to this question yet "How to read and update SQLite database using ListView in Android?" in other words how do you make the ListView Items Intent to the saved data in the SQLite Database and how to update them once you get to the other activity. I have tried many different ways to do this and so far they either don't work or crash my application. Can someone please help or at least lead me to the right

CRUD: my `find()` function on a SQLite implementation is never executed

最后都变了- 提交于 2019-12-13 08:56:18
问题 In a small app that intercepts SMS and persists them in a local database, I'm trying to implement a find method in my DAO. this my all my CRUD code : public class CSmsReceiverDAO implements IDAO<CSmsReceived> { private SQLiteDatabase bdd; private CMaBaseSQLite cMaBaseSQLite; private static final String NOM_BDD = "sms.db"; private static final int VERSION_BDD = 1; private static final String COL_ID = "ID"; private static final int NUM_COL_ID = 0; private static final String TABLE_SMS_SENT =

Android Sqlite onupgrade delete table from database

那年仲夏 提交于 2019-12-13 08:36:52
问题 I am using prepopulated database in my app and i have created two tables, Dictionary and Bookmark table . Dictionary table has the data i want to show and the Bookmark table saves the data if the user marks something as Favourite. What i want to do is when onupgrade method is called update the data in dictionary table and save the data in Bookmark table. Can anyone give me example to do that. P.S. I don't have much experience with Sqlite 回答1: The following is the code as used for the answer

Can't copy pre-created db from assets

六月ゝ 毕业季﹏ 提交于 2019-12-13 08:36:19
问题 android cant copy my pre create db from assets , the old db still exist in data/data/packagename/dabases, i want to change old db with new one ive tried to change this.getReadableDatabase(); into SQLiteDatabse db = this.getReadabledatabase() if (db.isOpen()){ db.close(); } public void createDatabase(){ boolean dbExist = checkDatabase(); if(!dbExist){ this.getReadableDatabase(); SQl try { copyDatabase(); }catch (IOException e){ Log.e(this.getClass().toString(),"eror kopi"); throw new Error(

SQLite Combine Value of Two Columns

拜拜、爱过 提交于 2019-12-13 08:33:56
问题 I am trying get data from database based on some logic, here is the query String sql = "SELECT pr.number, pr.u_id from pro_cap pr " + "LEFT OUTER JOIN pending p " + "WHERE p.mobile_id = pr.u_id+pr.infant_no "; Where, value of mobile_id in pending table is 4711 And value of u_id is 471 and value of number is 1 in pro_cap table I suppose to get data from database where 4711 = 4711, but unable to get... 回答1: For concatenating two or more columns use || operator. Change your query as below :

How to retrieve an image from a SQLite database?

*爱你&永不变心* 提交于 2019-12-13 08:15:40
问题 I am storing an image taken from camera into sqlite database can anybody help me to retrieve the same image and i want to show that image in a image view. Here is my Database handler class method for saving the image public long insert(Bitmap img ) { SQLiteDatabase base=this.getWritableDatabase(); byte[] data = getBitmapAsByteArray(img); // this is a function ContentValues value=new ContentValues(); value.put("image",data); long a= base.insert("Mypic", null, value); System.out.println("check1

SQLiteException using WHERE “ +KEY_Date+”='“+date+”'" [duplicate]

一世执手 提交于 2019-12-13 06:45:28
问题 This question already has answers here : Convert java.util.Date to String (18 answers) Closed 2 years ago . This is on my selectedDayChange on my mainactivity.java date= year +""+ month +""+ dayOfMonth; allfood food = new allfood(); food.Date="DATE_"+date; double a = repo.totalFat(food); Toast.makeText(getApplicationContext(), "" +a, Toast.LENGTH_LONG).show(); While this is on my repo.java public double totalFat(allfood date){ SQLiteDatabase db = dbHelper1.getReadableDatabase(); String query

Unable to convert BLOB to String using Loadermanager in android

心不动则不痛 提交于 2019-12-13 06:09:03
问题 I have a table with following structure. public static final String TABLE_NAME = "contact"; public static final String ID = "_id"; public static final String DEVICE_ID = "device_id"; public static final String NAME = "name"; public static final String CONTACT = "contact"; public static final String IMAGE = "image"; private static final int VERSION = 1; private static final String CREATE_TABLE_QUERY = "CREATE TABLE " + TABLE_NAME + "( " + ID + " INTEGER PRIMARY KEY , " + DEVICE_ID + " TEXT NOT