mercredi 20 mai 2015

RelativeLayout on click

I have added RelativeLayouts dynamically to my activity. The number of RelativeLayouts is equal to the number of items in my list.. below is the code:

RelativeLayout rt;
for(int i = 0; i < Names.size(); i++)
    { 
      rt=new RelativeLayout(this);
    }

Now if I have 7 items in list hence 7 RelativeLayouts, I want to set click event on each of them. So I did:

rt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //some code
        }
    });

Butthe click event is working only for the last layout.. I want it on each layout.. How can I achieve it? Please help. Thanx in advance.

Aucun commentaire:

Enregistrer un commentaire