EditText Settext not working with Fragment

后端 未结 5 1883
花落未央
花落未央 2020-12-01 03:36

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

5条回答
  •  Happy的楠姐
    2020-12-01 04:13

    As mentioned earlier, the EditText appears to have an issue with resetting text in onCreateView.

    This is because once a fragment is created , till the time we remove it from the backstack, its method onResume would be called as the view is not created again.

    So the solution here is to reset the text in onResume. This will work on all times even if u lock and unlock ur screen while that fragment is open or you are coming back from another fragment

    However if you are setting this data from a bundle it is better tonsave that value in an instance variable cause the bundle might come null amd u can gett null pointer issues then

提交回复
热议问题