Android片段中的EditText值不会刷新

Luk*_*s H 7 android fragment android-edittext android-viewpager

我正在使用Viewpager在3之间切换fragments,一切正常,除了刷新第二个标签(或fragment).在这个标签中,我有一张图片,一些静态Textviews,一些动态TextViews和一些EditText字段.

每次选择第二个选项卡时,都会调用setText()所有动态字段.TextView组件和微调器正在刷新并更新其内容,但EditText元素则不会.我不明白为什么这些字段没有更新.标签更改后,我呼吁notifiyDataSetChanged()TabsAdapter.onViewCreated()每次我更改选项卡时都会调用它.在onViewCreated()第二个片段中,我正在改变元素的内容.

那是我片段的代码:

 @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;
}
Run Code Online (Sandbox Code Playgroud)

正如我之前提到的,我的Image,TextView和Spinner Elements正在刷新它们的内容.我还检查了所有变量的内容,除了这些EditText元素外,一切似乎都很好.如果我将EditText元素转换为TextView,则内容正在改变(在代码中但不在GUI中).让我绝望的是,EditText在我第一次设置值时刷新.

有谁有想法,我怎么能刷新我的EditText领域的内容?

J.D*_*.D. 11

我不确定,但尝试onResume()将文本设置为恢复状态.

或尝试

选项卡更改上的Intent.FLAG_ACTIVITY_CLEAR_TOP.