0

大家好,我有一个我想在片段中显示的项目列表。从我想在下一个片段中显示的项目中选择一个项目后。我有代码,这工作正常。但我想在用户单击设备的后退按钮后返回相同的片段列表。

private AttendeeListAdapter attendeeListAdapter = null;
private List<DTO> attendeeDTOList;
private boolean showBookmarkedOnly=false;
private Fragment details;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MyListFragment list = new MyListFragment();
    attendeeDTOList=ProfileDAO.getInstance().getRecords(DBHandler.getInstance(getActivity()).getDBObject(0),showBookmarkedOnly);
    attendeeListAdapter = new AttendeeListAdapter(getActivity(),attendeeDTOList);
    list.setListAdapter(attendeeListAdapter);
     getChildFragmentManager()
     .beginTransaction()
     .add(R.id.content_frame, list)
     .commit();
    list.setOnItemClickListener(new OnItemClickListener() 
    {
        @Override public void onItemClick(AdapterView<?> l, View v, int position, long id) {
          // Create details fragment based on clicked item's position
            details = new AttendeeFragmentDetails();
               getChildFragmentManager()
              .beginTransaction()
              .replace(R.id.content_frame, details)
              .addToBackStack(null)
              .commit();
            final Bundle arguments = new Bundle();
            arguments.putSerializable("ProfileDTO", (ProfileDTO)attendeeDTOList.get(position));
            details.setArguments(arguments);
        }

    });

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // There has to be a view with id `container` inside `wrapper.xml`
    return inflater.inflate(R.layout.fragment_attendee_framelayout_list, container, false);
}

public static class MyListFragment extends ListFragment
{

    private OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener l)
    {
        this.listener = l;
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {
        if(listener != null)
        {
          listener.onItemClick(l, v, position, id);
        }
    }
}
4

0 回答 0