I use Viewpager to switch between 3 fragments , everything works fine, except for updating the second tab (or fragment ). On this tab, I have an image, some static Textviews , some dynamic Textviews and some EditText .
Each time the second tab is selected, setText() will be called in all dynamic fields. The TextView and spinner components update and update their contents, but the EditText elements do not. I do not understand why these fields are not updated. After changing the tab, I call notifiyDataSetChanged() on the TabsAdapter . It calls onViewCreated() every time I change the tab. In onViewCreated() second fragment, I change the contents of the elements.
Here is the code for my snippet:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { hA = (HelloAndroidActivity)this.getSherlockActivity(); appState = ((TestApplication)this.getSherlockActivity().getApplicationContext()); final PersistenceHelper pH = new PersistenceHelper(appState); m = pH.readMitarbeiter(toDisplay); // Inflate the layout for this fragment v = inflater.inflate(R.layout.detailfragment, container, false); if(m==null) { //If Mitarbeiter is empty pH.closeDB(); return v; } //Inflating Elements employeeName = (TextView)v.findViewById(R.id.employee_name); cDate = (TextView)v.findViewById(R.id.department); currentPlace = (TextView)v.findViewById(R.id.place_label); comment_text = (EditText)v.findViewById(R.id.comment_text); reachable = (EditText)v.findViewById(R.id.reachable_text); state = (Spinner)v.findViewById(R.id.spinner_state); durchwahl = (EditText)v.findViewById(R.id.durchwahl); department = (EditText)v.findViewById(R.id.department_edit); email = (EditText)v.findViewById(R.id.email_edit); img = (ImageView)v.findViewById(R.id.userPic); changeData = (Button)v.findViewById(R.id.changeButton); //Setting Elements employeeName.setText(m.getL_name()); currentPlace.setText(m.getStatus()); comment_text.setText(m.getBemerkung()); reachable.setText(m.getErreichbar()); email.setText(m.getS_name()+""); durchwahl.setText(m.getDurchwahl()+"",TextView.BufferType.EDITABLE); department.setText(m.getFunktion(),TextView.BufferType.NORMAL); //Spinner String[] values = { "Anwesend", "Mittagspause" , "Ausser Haus" , "Dienstreise", "Krankenstand" ,"Zeitausgleich", "Urlaub","Abwesend" }; ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this.getSherlockActivity(), android.R.layout.simple_spinner_item,values); state.setAdapter(spinnerArrayAdapter); state.setSelection(StateMapper.returnState(m.getStatus())); //Image //....... return v; }
As I mentioned earlier, my images, TextView, and Spinner Elements update their content. I also checked the contents of all the variables, everything seems fine except for these EditText elements. If I insert EditText elements into a TextView, the content changes (in the code, but not in the GUI). What also makes me desperate is that EditText updates the first time I set the value.
Does anyone have an idea how I can update the contents of my EditText fields?