I am looking at creating a Dialog with a bundle of data. This all work correctly.
I have a number of buttons when clicked opens the dialog with the data and can then be updated.
Trouble I am having is it does not matter which button I press the bundle is only the data for the last row. Any ideas on getting the correct data passed to the Dialog for each button.
I was thinking down the line of setting an id for each view as I pass through the loop but unsure how to call that back again
Code:
for (int i = 0; i < nameInfo.size(); i++) {
// creating the views
View viewItem = (View) inflater.inflate(R.layout.view_item, null);
nameView = (TextView) viewItem.findViewById(R.id.title);
nameView.setId(i);
value1View = (TextView) viewItem.findViewById(R.id.value1);
value1View.setId(i);
value2View = (TextView) viewItem.findViewById(R.id.value2);
value2View.setId(i);
updateButton = (Button) sightmarkView.findViewById(R.id.updatebutton);
updateButton.setId(i);
// Getting the values
nameValue = nameInfo.get(i).toString();
value1 = db.getvalue1('1', nameInfo.get(i).toString());
value2 = db.getvalue2('2', nameInfo.get(i).toString());
// update fields
nameView.setText(nameValue);
value1View.setText(String.valueOf(value1));
value2View.setText(String.valueOf(value2));
updateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int updateButtonId = updateButton.getId();
bundle = new Bundle();
bundle.putString("name", nameValue);
bundle.putFloat("value1", value1);
bundle.putFloat("value2", value2);
showDialog(SIGHTMARK_DIALOG_ID, bundle);
}
});
pMainlayout.addView(viewItem);
}
Thanks for your time
In each loop (from the
for), you are redefining the values ofnameValue,value1andvalue2.To fix the problem, just change your code to match this: