Search code examples
androidandroid-edittext

EditText Settext not working with Fragment


I have fragments for 3 states of a screen; Add, Edit and View. In Add, I create an entity and save it. Next time I open it in View mode and set the entity name using

EditText entityName = (EditText) view.findViewById(R.id.entityName);    
entityName.setText(entity.getEntityname());

I click on the edit button from View mode to open the Edit mode. I change the entity name here and save it. This brings me back to the view screen. But I find the entity name is not updated. I debug and found that entity.getEntityname() is having correct value. I am not sure why the edit text does not take new value.

Any ideas?

Note: I am using android version 2.2


Solution

  • The EditText appears to have an issue with resetting text in onCreateView. So the solution here is to reset the text in onResume. This works.

    Also there's an issue in onActivityCreated. I reset edittext's content in onStart and it works. [credits to @savepopulation]