android - 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)
}
}
解决方案
推荐阅读
- python - pytorch 无法使用 gpu
- node.js - TypeError:无法读取未定义的nodejs请求http的属性'0'
- r - 将字符串 2000 年 1 月 1 日上午 12:00 转换为 r 中的日期时间
- latex - Latex 缩进会为每个备用页面自动更改
- powerbi - Powerbi Desktop:如何在不选择每个项目的情况下进行过滤?
- javascript - 在数组中按特定顺序分配颜色
- javascript - 从 Array.prototype.indexOf.call 中排除某些元素
- java - Thymeleaf - 如何显示未包含在 th:text 中的文本
- wordpress - 如何创建简码以在页面部分显示 Custon Taxonomy 的术语及其图像?
- bash - 脚本在容器中失败,但奇异性返回 0(无错误)