Saturday 17 August 2013

findViewById() in OnActivityResult function causes crash

findViewById() in OnActivityResult function causes crash

In onActivityResult function I create layout and button in this layout.
And when I press the button, I want to edit data in it by calling a new
activity. I received data from new activity and want to find button by id
to apply changes. But function findViewById causes crash of my
application. How can I fix it?
This is part of my code:
if(requestCode == EditingMedicine)
{
if(resultCode == RESULT_OK)
{
int _id = data.getIntExtra(AddEditMedicineActivity.Id, -1);
String medName =
data.getStringExtra(AddEditMedicineActivity.medName);
String medTime =
data.getStringExtra(AddEditMedicineActivity.medTime);
Button btn = (Button)findViewById(_id);
btn.setText(Html.fromHtml(medName + " <br/>" + medTime));
}
}
Thanks.

No comments:

Post a Comment