Converting SimpleCursorAdapter code from Java to Kotlin

225 Views Asked by At

I'm trying to reuse the following Java code in Kotlin:

        SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this, 
                R.layout.textsummarylistentry, mMatrixCursor, 
                from, to);
        setListAdapter(scAdapter);

When I copy and paste this into a Kotlin class which extends ListActivity, and accept Android Studio's automatic conversion to Kotlin I get the following:

        var scAdapter : android . widget . SimpleCursorAdapter ? =
                SimpleCursorAdapter(
                    this,
                    R.layout.textsummarylistentry, mMatrixCursor,
                    from, to
                )
        listAdapter = scAdapter

There are numerous errors which Quick Fix is unable to resolve. How should I correct this code?

1

There are 1 best solutions below

1
Priyank-py On BEST ANSWER

I think this should work:

var scAdapter = SimpleCursorAdapter(this, R.layout.textsummarylistentry, mMatrixCursor, from, to)
setListAdapter(scAdapter)

Share the error message if this doesn't works.