Good guys, I have a recyclerView with different images, I want to press any image and it is reflected in another activity, my problem is that when pressing on any image the same image is always displayed.
class LugaresFragment : Fragment(), RecyclerAdapter.OnClickListener {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_lugares, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val list = ArrayList<Sitios>()
list.add(Sitios(R.drawable.filesharing, "Holaa","hola2"))
list.add(Sitios(R.drawable.travelcase, "Holaa","hola2"))
//Metodo para mostrar los elementos de recyclerView
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = RecyclerAdapter(context,list,this)
}
override fun onImageClik(img: Int) {
val intent = Intent(context,ImageDetail::class.java)
intent.putExtra("CLAVE",img)
startActivity(intent)
}
override fun onItemClik(title: String) {
TODO("Not yet implemented")
}
}
class ImageDetail : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image_detail)
intent.getStringExtra("CLAVE")?.toInt()?.let { imageCardView.setImageResource(it) }
}
}