在第二个片段视图之后更新微调器控件

时间:2019-06-26 20:47:14

标签: java android android-fragments spinner

我有一个带有微调控件的Android / Java应用程序,并且第一次查看Fragment时它会加载微调控件。然后,如果我加载另一个视图,然后用户返回,则微调框为空,但数据不是。如何确保第二个视图上的数据已更新?

启动片段的主要活动

private static Fragment;

private void LoadFragment()
{
    m_fragmentPerson = PersonFragment.newInstance(getApplicationContext());
    m_fragmentPersonDisplayOptions.setRetainInstance(true);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.frame_container, PersonFragment.newInstance(getApplicationContext());
    transaction.commit();
}

MyFragment.java

private static Spinner m_spnPeople;
private static List<String> m_lstPeopleForSpinner = new ArrayList<String>();
private ArrayAdapter<String> m_daPeople; 

private void DownloadData()
{
    //... Download code ...
    // puts data into m_lstPeopleForSpinner
    // shows there is data on the second view

    m_spnPeople = (Spinner) getView().findViewById(R.id.spnPeople);
    m_daPeople = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, m_lstPeopleForSpinner);
    m_spnPeople.setAdapter(m_daPeople);


    m_lstPeopleForSpinner.clear();
    for (int j = 0; j < m_lssRawPersonInfo.size(); j++)
    {
        String sLongName = m_lssRawPersonInfo.get(j).LongName;
    }
}

我看到m_lssRawPersonInfo中的数据保留在第二个视图上,但Spinner控件仍然不会加载数据。

我尝试使用m_daPeople.notifyDataSetChanged();但它不会改变任何东西。

感谢您提供的任何帮助!

0 个答案:

没有答案