SimpleCursorAdapter and strftime

22 Views Asked by At

I'm building an app that starts with a db from the assets folder. In there are columns with dates, like YYYY-MM-DD.

In the app I want to show the dates in DD-MM format in a listview, ordered by date starting from now. The part that gives me a headache is the DD-MM format.

I've been fiddling around with strf like this:

   val n1 = arrayOf<String>("strftime('%Y/%m/%d', zaaidatum\" )+ \">= date('now'))

but im starting to wonder if it is even possible? (Log says syntaxerror: unrecognized token: "[Ljava.lang.String;@bbe7390)

This is the code in my SqliteDbHelper class:

fun getZaai(): Cursor? {
    return this.writableDatabase.query("TAKENLIJST", null, "zaaidatum" + ">= date('now', 'localtime')",null, null, null, "zaaidatum")
}

This is the code in my Fragment:

private fun zaaiListView() {
    var sca: SimpleCursorAdapter? = null
    var cursor: Cursor? 
    val listview = binding.listviewTaken
    val db = SqlLiteDbHelper(requireContext())
    cursor = db.getZaai() /* Gets the data to be listed */
    /* If first time then setup the adapter listeners etc */if (sca == null) {
        sca = SimpleCursorAdapter(
            requireContext(),
            R.layout.fragment_taken_rec_card,
            cursor,
            arrayOf("groente", "aantal", "blok", "bed", "zaaidatum"),
            intArrayOf(R.id.taken_groente, R.id.taken_aantal, R.id.taken_blok, R.id.taken_bed, R.id.taken_datum ),
            0
        )



        listview.adapter = sca // attach the adapter to the listview
        // setup On Item Click to start the update activity passing the id
        listview.onItemClickListener =
            OnItemClickListener { adapterView, view, i, l ->
                val intent = Intent(context, UpdateActivity::class.java)
                intent.putExtra("my_id_extra", l)
                startActivity(intent)
            }
        // setup the on Item LONG Click to delete a row
        listview.onItemLongClickListener =
            OnItemLongClickListener { adapterView, view, i, l ->
               // db.delete(l)
                zaaiListView() // after deletion refresh the data
                true
            }
    } else {
        sca?.swapCursor(cursor) // if not the first time just tell the adapter the data has changed
    }
}
0

There are 0 best solutions below