Вы должны проверить id
вида, чтобы различать их. Например, если id
из ImageButton
, для которого вы хотите перейти ко второму activity
, равно pokemon , то попробуйте так:
fun onclickImage(view: View) {
if(view.id == R.id.pokemon) {
val myIntent = Intent(this, Details::class.java)
myIntent.putExtra("pokemon", "Pokemon")
startActivity(myIntent)
}
}
Если вы такжечтобы сделать это с помощью tag
, вы должны установить tag
либо в XML, либо в коде. Затем вы можете проверить это с помощью tag
<ImageButton
android:id="@+id/pokemon"
android:tag="Pokemon"
android:onClick="onclickImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Затем отметьте tag
и примите решение.
fun onclickImage(view: View) {
val pokemonName = view.tag.toString()
if(pokemonName.equals("Pokemon", true)) {
val myIntent = Intent(this, Details::class.java)
myIntent.putExtra("pokemon", pokemonName)
startActivity(myIntent)
}
}