**APP EM ANDROID STUDIO KOTLIN**
Pessoal sou novato do novato no android studio kotlin tambem no java…
Estou desenvolvendo uma aplicativo sobre compras em supermercado…
Do inicio até o comentado serrilhado não tem nenhum problema.
Aparece a ListView com todas os produtos…
O meu problema esta que quando dou click em qualquer linha da ListView não estou conseguindo marcar checktextview…
Agradeço quem possa me ajudar…
Obrigado
import android.os.Bundle
import android.view.View
import android.widget.CheckedTextView
import android.widget.ListView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.cursoradapter.widget.SimpleCursorAdapter
class ListaActivity : AppCompatActivity() {
//var inflter: LayoutInflater? = null
var value: String? = null
private val names: Long? = null
private var dbManager: DBManager? = null
private var listView: ListView? = null
private var adapter: SimpleCursorAdapter? = null
private val from = arrayOf(DatabaseHelper._ID, DatabaseHelper.SUBJECT, DatabaseHelper.DESC)
private val to = intArrayOf(R.id.id, R.id.title)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_lista)
dbManager = DBManager(this)
dbManager!!.open()
val cursor = dbManager!!.fetch()
listView = findViewById<View>(R.id.list_view) as ListView
listView!!.emptyView = findViewById(R.id.empty)
adapter = SimpleCursorAdapter(this, R.layout.activity_view_record, cursor, from, to, 0)
adapter!!.notifyDataSetChanged()
listView!!.adapter = adapter
listView!!.setOnItemClickListener { parent, view, position, id ->
Toast.makeText(this, "Clicked item : $position", Toast.LENGTH_SHORT).show()
//--------------------------Toast para cima funciona perfeitamente o problema e abaixo---------------------------------------------------------------//
}
val checkedTextView = findViewById(R.id.checkedTextView)
if (checkedTextView != null) {
checkedTextView.isChecked = false
checkedTextView.setCheckMarkDrawable(android.R.drawable.checkbox_off_background)
checkedTextView.setOnClickListener {
checkedTextView.isChecked = !checkedTextView.isChecked
checkedTextView.setCheckMarkDrawable(if (checkedTextView.isChecked) android.R.drawable.checkbox_on_background else android.R.drawable.checkbox_off_background)
val msg = getString(R.string.pre_msg) + " " + getString(if (checkedTextView.isChecked) R.string.checked else R.string.unchecked)
Toast.makeText(this@ListaActivity, msg, Toast.LENGTH_SHORT).show()
}
}
}
}