Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

android - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...