单击 ListView ListItem 中的 ImageView 并获取位置? [英] Click ImageView within a ListView ListItem and get the position?

查看:9
本文介绍了单击 ListView ListItem 中的 ImageView 并获取位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,当 ListItem 被点击时,我会抓住它的位置并将它传递给我的 StopsScheduleActiviy.我想检测该 ListItem 的 ImageView 何时被单击,以便我可以启动我的 MapActivity 并将位置传递给它.

Currently, when the ListItem is clicked I grab its position and pass it to my StopsScheduleActiviy. I would like to detect when the ImageView of that ListItem is clicked so that I can launch my MapActivity instead and pass it the position.

基本上:单击 ImageView 启动 MapsActivity,否则单击 ListItem 上的任何其他位置启动 StopsScheduleActivity.在这两种情况下,我都需要这个职位.我怎样才能做到这一点?

Basically: Click the ImageView launch MapsActivity, otherwise click anywhere else on ListItem launch StopsScheduleActivity. In Both cases I need the position. How can I do this?

这是我当前的 onItemClick 侦听器.

Here is my current onItemClick listener.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    Intent myIntent = new Intent(this, StopsScheduleActivity.class);
    myIntent.putExtra("stop", stops.get(position));

    startActivity(myIntent);

    Log.i("Winnipeg Bus", "Stop item #" + id + " clicked.");
}

这是我的 ListView,带有我想收听点击次数的 ImageView 的地图.谢谢!

Here is my ListView with a map for an ImageView that I want to listen to for clicks. Thanks!

推荐答案

对于 ImageView 的 Click You have to make a custom adapter for your listview.

在adpater 的getView() 方法中,只需编写一个imageView 的onClick(),然后从该imageview 的onClick() 开始您的新活动.

And in adpater's getView() method just write a imageView's onClick(), And start your new activity from that imageview's onClick().

对于自定义列表,只需查看本教程 Android 系列:自定义 ListView 项目和适配器...

For custom list just look at this tutorial Android Series: Custom ListView items and adapters ..

这篇关于单击 ListView ListItem 中的 ImageView 并获取位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆