I have a for loop in Android. I create Buttons and button click events in loop. The codes are in below.
The codes:
for(ii = 0; ii < yardimarray.size(); ii++){
Button yardimmtv = new Button(yardim.this);
yardimmtv.setText(yardimarray.get(ii));
yardimmtv.setTextColor(Color.WHITE);
yardimmtv.setTextSize(17);
yardimmtv.setLayoutParams(yardimtvlp);
yardimmtv.setBackgroundResource(tvalue.resourceId);
yardiml.addView(yardimmtv);
iii = ii + 1;
yardimmtv.setOnClickListener ( new View.OnClickListener () {
public void onClick (View yardimmv){
Intent yardimbgecis = new Intent(yardim.this, yardimbilgi.class);
yardimbgecis.putExtra("yardimid", String.valueOf(iii));
finish();
startActivity(yardimbgecis);
}
});
}
But yardimid is always 9 and loop run 9 times.
How I can resolve this problem?
I need your help.