Android Fragment 中的 EditText 值不刷新

2024-03-24

我正在使用Viewpager在 3 之间切换fragments,一切工作正常,除了第二个选项卡的刷新(或fragment)。在这个选项卡中,我有一张图片,一些静态的Textviews, 一些动态TextViews还有一些EditText fields.

每次选择第二个选项卡时,都会调用setText()在所有动态领域。 TextView 组件和微调器正在刷新和更新其内容,但 EditText 元素则不会。 我不明白为什么这些字段没有更新。选项卡更改后,我打电话notifiyDataSetChanged() in 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;
}

正如我之前提到的,我的 Image、TextView 和 Spinner Elements 正在刷新其内容。我还检查了所有变量的内容,除了这些 EditText 元素之外,一切似乎都很好。如果我将 EditText 元素投射到 TextView 中,内容就会发生变化(在代码中,但不在 GUI 中)。同样让我绝望的是,EditText 在我第一次设置值时刷新。

有谁知道我如何刷新我的内容EditText fields?


我不确定,但尝试一下onResume()并将您的文本设置为恢复状态。

or try

选项卡更改时的 Intent.FLAG_ACTIVITY_CLEAR_TOP。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Fragment 中的 EditText 值不刷新 的相关文章

随机推荐