I have 10 buttons and i want to set OnClickListener for all that buttons. Also with clicking on any button app will go another activity. I only post the buttons' definitions on the activity class. My code;
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);
Button button4 = (Button) findViewById(R.id.button4);
Button button5 = (Button) findViewById(R.id.button5);
Button button6 = (Button) findViewById(R.id.button6);
Button button7 = (Button) findViewById(R.id.button7);
Button button8 = (Button) findViewById(R.id.button8);
Button button9 = (Button) findViewById(R.id.button9);
Button button10 = (Button) findViewById(R.id.button10);
Button buttons[] = {button1, button2, button3, button4, button5, button6, button7, button8, button9, button10};
final String urlOfButtons[] = {"","","","","","","","","","",""};
final String titles[] = {"","","","","","","","","","",""};
JsonNode itemNode = jsonNode.path("Docs");
for(int i=0 ; i<itemNode.size() ; i++){
titles[i] = itemNode.get(i).path("Text").asText();
title = titles[i];
buttons[i].setText(title);
urlOfButtons[i] = itemNode.get(i).path("Link").asText();
url = urlOfButtons[i];
buttons[i].setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(HouseDetail.this, HouseDetailPdf.class);
intent.putExtra("title", title);
intent.putExtra("url", url);
startActivity(intent);
}
});
}
This only takes the last values of title and url normally. String url, title is defined on top of class. Every button i click the same value goes to other activity. I want 10 different values to add extra. So i want to add instead of title and url; titles[i] and url[i] as extra. I hope i'm clear.