I have listView and each element contains 1 button
When user presses some element of ListView (but not button) it works correctly and android shows toast: "Not button clicked, $position works correctly"
But I also need to make toast (and get position of button) when button is clicked in specific listView element. I tried to use view.imageViewButton.setOnClickListener inside of listV.setOnItemClickListener but in this scenario button worked only after I clicked a blank space to the left of the button.
listV.setOnItemClickListener { parent, view, position, id -> //I tried you use comented line to solwe my problem //view.imageViewButton.setOnClickListener { Toast.makeText(this, "button $position is clicked",Toast.LENGTH_SHORT).show() } Toast.makeText(this, "not button clicked, works correctly", Toast.LENGTH_SHORT).show()} How should I do to activate buttons when onCreate(savedInstanceState: Bundle?) starts?
My kotlin code:
class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) var db = DataBaseHelper(this) var cursor = db.returnLines() listV.adapter = SimpleCursorAdapter(this, R.layout.view_holder, cursor, arrayOf("imia"), intArrayOf(R.id.listNameView), 0) listV.setOnItemClickListener { parent, view, position, id -> //I tried you use comented line to solwe my problem //view.imageViewButton.setOnClickListener { Toast.makeText(this, "button $position is clicked",Toast.LENGTH_SHORT).show() } Toast.makeText(this, "not button clicked, $position works correctly", Toast.LENGTH_SHORT).show() }}