堆栈中的碎片值不重新绑定

时间:2014-05-07 08:52:49

标签: android android-fragments

我在Android应用程序中工作,我在我的活动中使用了两个片段。在第一个片段中,我将一个Android ListView与来自Web服务的值列表绑定,并在同一个ListView行中单击,将其重定向到第二个片段。当我从第二个片段中单击硬件后退按钮时,第一个片段列表视图中的值不会被分箱。

如何解决这个问题。

碎片类

public class BusFacilityFragment extends Fragment {

    private ListView mBusFacilityListView = null;
    private ArrayList<Site> mLstSites = null;
    @Override
    public void onAttach(Activity activity) {

        super.onAttach(activity);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.bus_facilitylistview, container,
                false);

        //new GetBusFacilityAsynk().execute();

        return view;
    }
}

活动类

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bustime_screen);

        BusFacilityFragment onedayFragment = new BusFacilityFragment();
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();

        transaction.replace(R.id.busfragment_Contanier, onedayFragment,
                "BusFacility");
        transaction.addToBackStack(null);
        transaction.commit();
                // The values in BusFacilityFragment are binded in this asynktask
        new GetBusFacilityAsynk().execute();
    }

从Fragmentactivity重定向到第二个片段

private void onListItemClick() {

        mBusFacilityListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Toast.makeText(getApplicationContext(),
                        mLstSites.get(position).SiteName, Toast.LENGTH_SHORT)
                        .show();

                BusSheduleFragment busSheduleFragment = new BusSheduleFragment();
                FragmentTransaction transaction = getSupportFragmentManager()
                        .beginTransaction();

                transaction.replace(R.id.busfragment_Contanier,
                        busSheduleFragment, "BusShedule");
                transaction.addToBackStack(null);
                transaction.commit();

            }
        });
    }

0 个答案:

没有答案