0
have a code: 
  
 val booksForDelete = arguments?.getParcelableArray("books")

  val builder = AlertDialog.Builder(activity)
        val checkedItem = -1

        builder.setTitle("Choose the book for DELETE")
        
            .setSingleChoiceItems(booksForDelete?.**map**(Book::title)?.toTypedArray(),checkedItem){dialog, which ->
                Toast.makeText(activity,"Choosen book: ${booksForDelete?.map { Book::title}?.get(which)}",Toast.LENGTH_SHORT).show()
            }

in the line ".setSingleChoiceItems..." a have a mistake - "map" marked. What's wrong?

P.S.

data class Book(val title: String, val id: Int) : Parcelable {
constructor(source: Parcel) : this(
        source.readString()!!,
        source.readInt()
)

2 Answers2

0

The expression booksForDelete?.map(Book::title)?.toTypedArray() is syntactically correct. However usually it's written in a more 'kotlin'-ic form:

booksForDelete?.map { it.title }?.toTypedArray()
user3159253
  • 16,836
  • 3
  • 30
  • 56
  • @Дмитрий Unfortunately, you don't provide any additional info regarding the error: what kind of error, what you expect to get and what you actually get and so on and so forth. I guess you're using an IDE like Intellij Idea: what does it say on the line? – user3159253 Jul 14 '20 at 05:13
  • thanks for answer. i take two arrays and solve my problem – Дмитрий Jul 14 '20 at 08:59
0

Please try to cast your Parcelable array to Array<Book>:

@Suppress("UNCHECKED_CAST") 
val booksForDelete = arguments?.getParcelableArray("books") as? Array<Book>
Sergio
  • 27,326
  • 8
  • 128
  • 149