androidlistviewandroid-listviewlistitem

Click ImageView within a ListView ListItem and get the position?


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.

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?

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.");
}

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

enter image description here


Solution

  • For ImageView's Click You have to make a custom adapter for your listview.

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

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