Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package elegion.com.secondappforcontentprovidertest
- import android.content.ContentValues
- import android.database.Cursor
- import android.net.Uri
- import android.os.Bundle
- import android.support.v4.app.LoaderManager
- import android.support.v4.content.CursorLoader
- import android.support.v4.content.Loader
- import android.support.v7.app.AppCompatActivity
- import android.util.Log
- import android.widget.TextView
- import android.widget.Toast
- class MainActivity: AppCompatActivity(), LoaderManager.LoaderCallbacks<Cursor> {
- lateinit var textView: TextView
- companion object {
- val urlAddress = "content://com.example.roomproject.musicprovider/album/1"
- }
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- textView = findViewById(R.id.tv_hello)
- textView.setOnClickListener {
- var contentValues = ContentValues()
- contentValues.put("id", 0)
- contentValues.put("name", "new Name")
- contentValues.put("release", "tomorrow")
- contentResolver.update(Uri.parse(urlAddress), contentValues, null, null)
- }
- supportLoaderManager.initLoader(12, null, this)
- }
- override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
- return CursorLoader(this,
- Uri.parse("content://com.example.roomproject.musicprovider/album"),
- null,
- null,
- null,
- null)
- }
- override fun onLoadFinished(loader: Loader<Cursor>?, data: Cursor?) {
- if (data != null && data.moveToFirst()) {
- val builder = StringBuilder()
- do {
- builder.append(data.getString(data.getColumnIndex("name"))).append("\n")
- } while (data.moveToNext())
- Toast.makeText(this, builder.toString(), Toast.LENGTH_LONG).show()
- }
- }
- override fun onLoaderReset(loader: Loader<Cursor>?) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement