首页 > 解决方案 > kotlin 中的列表视图 setOnItemClickListener

问题描述

因此,我尝试使用 setOnItemClickListener 在列表视图中单击,然后更改为另一个布局,从而带来我单击的 de 信息,但首先我什至无法更改布局。我试图从 Clube 去 clube_detalhado 但什么也没发生,甚至连祝酒都没有。

class Clube : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
    // Inflate the layout for this fragment
    val view = inflater.inflate(R.layout.clubes, container, false) as View

    val listView : ListView = view.findViewById(R.id.clubes_list)


    var names: ArrayList<NewsObject> = arrayListOf(
            NewsObject(R.drawable.sportingim, "Sporting","15 JOGOS 367 GOLOS"),
            NewsObject(R.drawable.manunited, "Manchester United","15 JOGOS 367 GOLOS"),
            NewsObject(R.drawable.realim, "Real Madrid","15 JOGOS 367 GOLOS"),
            NewsObject(R.drawable.juv, "Juventus","15 JOGOS 367 GOLOS"),
            NewsObject(R.drawable.selecao, "Seleção Nacional","15 JOGOS 367 GOLOS")
    )

    listView.adapter = MyCustomAdapter(requireContext(),names)


    listView.setOnItemClickListener {_,_, position, _ ->

        Toast.makeText(requireContext(),"burro", Toast.LENGTH_LONG).show()
        //val imagemnova: String = names[position].img.toString()
        //val titulonovo: String = names[position].title
        //val descrinova: String = names[position].desc
        val intent = Intent(requireContext(), Clube_detalhado::class.java)
        startActivity(intent)
    }


    return view

}

这是我的俱乐部_detalhado

class Clube_detalhado : AppCompatActivity() {

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

标签: androidlistviewkotlinonclicklistener

解决方案


推荐阅读