Content Provider – Part 1 – Contract class

Content Provider – Part 1 – Contract class

A Content Provider(CP) is a component that encapsulates data, expose them through a standard API and optionally make these data available to other applications. CP is independent of a data storage, which can be local, remote or mixed. Contract class We need a CP contract class to describe the data exposed from the CP(tables, columns, SQL creation strings, etc). The table information is in nested classes, a separate class for each table. Those classes should describe how to access the table, the table’s URI and the column name. The table…

Content Provider – Part 1 – Contract class Read More

Android – SQLite insert, delete and tip

Android – SQLite insert, delete and tip

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

Android – SQLite update

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

ANDROID – RECYCLERVIEW ADAPTER with Cursor PART 2

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

Android – Populate a spinner with a SimpleCursor Adaptor

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