Android – SQLite insert, delete and tip

SQLite insert delete, <span>Android – SQLite insert, delete and tip</span>, KandZ

You can read about SQLiteOpenHelper here. insert To insert a record in a table you need: a set of values using ContentValues class the table name delete To delete a record from a table you need: the table name selection string selection arguments array Tip It is not recommended to execute any database operation on the Main/UI thread. So use AsyncTask, override the doInBackground method and execute the database operations. THE END!!! Android – SQLite insert, delete and tip

Android – SQLite insert, delete and tip Read More

Android – SQLite update

SQLite insert delete, <span>Android – SQLite insert, delete and tip</span>, KandZ

If you haven’t created yet SQLite helper class that extends SQLiteOpenHelper read this post. To update an existing record/row in SQLite table you need: table name column names that will be updates the new column values selection criteria I will first create a method that has 3 parameters, SQLiteDatabase, an id and an object that has all the values to be updated: Next, I will use ContentValues class to store a set of values so later used with update: Now create one string for the selection and one string array…

Android – SQLite update Read More

ANDROID – RECYCLERVIEW ADAPTER with Cursor PART 2

SQLite insert delete, <span>Android – SQLite insert, delete and tip</span>, KandZ

You can read Part 1 here. Next, step of the recyclerView implementation is to implement the recyclerView Adapter. It has two main jobs: to create the item views and return them to the recyclerView and to populate the item views. RecyclerView creates the items that are visible but also for some before and after. Instead of creating new items, it takes one item that is last/old, moves it to the front and then recyclerView populates it with new data. In other words, the adapter recycles the views/items Create a recyclerView Adapter…

ANDROID – RECYCLERVIEW ADAPTER with Cursor PART 2 Read More

Android – Populate a spinner with a SimpleCursor Adaptor

SQLite insert delete, <span>Android – SQLite insert, delete and tip</span>, KandZ

Let’s first create a Spinner view in the layout XML file Get the reference of the spinner: Now create a query with the data you want to populate the spinner Now create a new SimpleCursorAdapter: this – context android.R.layout.simple_list_item_1 – a standard layout item new String[] {GamesContract.GameEntry.COL_TITLE} – use the value of this columng new int[]{android.R.id.text1} – the value should be displayed on this view Now connect the cursor to the simpleCursorAdapter: Set the adapter to the spinner: You can set/change the resource for the dropdown using setDropDownViewResource: THE END!!!…

Android – Populate a spinner with a SimpleCursor Adaptor Read More

Android – SQLiteDatabase.query

SQLite insert delete, <span>Android – SQLite insert, delete and tip</span>, KandZ

query method gives you access to the data of a SQLiteDatabase. You specify what you want to return from a table, it is like SQL select, and it returns back a Cursor. You can specify table name, columns, selection, groupBy, having, orderBy and limit. The syntax is: Cursor provides access to the query results and allows us to go through the results row by row. The cursor maintains a position and we should position it to a specific row, also in the beginning using moveToNext. Some other methods are: moveToPrevious,…

Android – SQLiteDatabase.query Read More