Unable to get the click event for multiple ImageView which is displayed by using a for loop


Last Updated:

  1. chiranjib

    chiranjib New Member This Topic's Starter

    Joined:
    Apr 20, 2010
    Messages:
    3
    Likes Received:
    0
    Hi All,

    I am displaying multiple ImageView by using a for loop . Now I want to get the clickEvent for a specific ImageView . How can I get the event ?????

    ex: I have printed 10 ImageViews one after another vertically on the screen. If I click on the 5th ImageVirew , how can I get the event for that ??
    I have provided the following code which is unable to fetch the event.
    Kindly reply.
    Also inform me if there is any other alternatives.



    ImageView nameImageView = null;
    for (int i = 0; i <= response.size() - 1; i++) {

    // Details Button
    nameImageView = new ImageView(this);
    RelativeLayout.LayoutParams lpDetailsOption = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
    lpDetailsOption.setMargins((screenWidth / 12),
    (screenHeight / 3) - 20, 0, 0);
    nameImageView .setId(i);
    nameImageView .setClickable(true);
    nameImageView .setImageResource(R.drawable.icon);
    relLayout.addView(nameImageView , lpDetailsOption);
    nameImageView
    .setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
    int j = nameImageView .getId();

    }
    });



    Warm Regards,
    Chiranjib
     

    Advertisement

Share This Page

Loading...