Mutablelist<Int> cannot be Invoked as a Function. What do I do?

Asked

Viewed 32 times

1

package com.example.app.views

import android.app.DatePickerDialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import android.widget.DatePicker
import android.widget.Toast
import com.example.app.Entities.PriorityEntity
import com.example.app.R
import com.example.app.business.PriorityBusiness
import com.example.app.business.TaskBusiness
import kotlinx.android.synthetic.main.activity_app_form.*
import java.lang.Exception
import java.text.SimpleDateFormat
import java.time.Month
import java.time.Year
import java.util.*

class AppFormActivity : AppCompatActivity(), View.OnClickListener, DatePickerDialog.OnDateSetListener {




    private lateinit var mTaskBusiness: TaskBusiness
    private lateinit var mPriorityBusiness: PriorityBusiness
    private var mlstPrioritiesEntity: MutableList<PriorityEntity> = mutableListOf()
    private var mlstPrioritiesId: MutableList<Int> = mutableListOf()

    private val mSimpleDateFormat: SimpleDateFormat = SimpleDateFormat("dd/MM/yyyy")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_app_form)

        mPriorityBusiness = PriorityBusiness(this)
        mTaskBusiness = TaskBusiness(this)

        loadPriorities()

        setListeners()



    }

    override fun onClick(view: View) {

        when(view.id){

            R.id.ButtonDate -> {

                openDatePickerDialog()

            }

            R.id.ButtonSave ->{
            handleSave()

            }

        }

    }


    override fun onDateSet(view: DatePicker, year: Int, month: Int, dayOfMonth: Int) {

        val calendar = Calendar.getInstance()
        calendar.set(year, month, dayOfMonth)
        ButtonDate.text = mSimpleDateFormat.format(calendar.time)
    }

    private fun setListeners(){

        ButtonDate.setOnClickListener(this)
        ButtonSave.setOnClickListener(this)

    }

    private fun handleSave(){

        try {

        val description = EditDescription.text.toString()

        val priorityId = mlstPrioritiesId{SpinnerPriority.selectedItemPosition} **//ta dando erro quando eu insiro o selectedItemPosition**





        }catch (e:Exception){
            Toast.makeText(this, getString(R.string.erro_inesperado), Toast.LENGTH_LONG).show()
        }



    }

    private fun openDatePickerDialog(){
        val c = Calendar.getInstance()
        val year = c.get(Calendar.YEAR)
        val month = c.get(Calendar.MONTH)
        val dayOfMonth = c.get(Calendar.DAY_OF_MONTH)

        DatePickerDialog(this, this, year, month, dayOfMonth).show()


    }


    private fun loadPriorities(){

         mlstPrioritiesEntity = mPriorityBusiness.getList()

        val lstPriorities = mlstPrioritiesEntity.map { it.description }
        mlstPrioritiesId= mlstPrioritiesEntity.map { it.id }.toMutableList()

        val adapter = ArrayAdapter<String> (this, android.R.layout.simple_spinner_dropdown_item, lstPriorities)
        SpinnerPriority.adapter = adapter


    }


}
  • Could you include a description of the problem? And stack trace?

1 answer

0


You must use square brackets to access an element of a list (as if it were an array):

val priorityId = mlstPrioritiesId[SpinnerPriority.selectedItemPosition]

This is the Indexed access Operator, a syntactic sugar equivalent to

val priorityId = mlstPrioritiesId.get(SpinnerPriority.selectedItemPosition)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.