Search code examples
javaandroidfragmentdestructorslidingdrawer

SlidingMenu ListFragment menu destroyed after OnItemClickListener fires


I'd like to start off by saying this is my first largish Android app...

I'm using the third-party library SlidingMenu and everything is working great except for one thing: when the user taps a list item in the "basement" menu, that ListFragment is destroyed. I set logs in all of the construction/deconstruction methods of the ListFragment to log the activity. Here's an image of the log, edited to show when the touch event occurred.

enter image description here

My ListFragment class is setup like so:

public class BasementFragment extends ListFragment implements PictureCallback {
    BasementAdapter mAdapter;
    RelativeLayout mHeader;
    ArrayList<String> titles;
    ImageView mImageButton;

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d("BASEMENTFRAGMENT", "onCreateView");
    ListView view = (ListView) inflater.inflate(R.layout.basement, null);
    mHeader = (RelativeLayout) inflater.inflate(R.layout.basement_header, null);
    view.addHeaderView(mHeader);

    mImageButton = (ImageView) mHeader.findViewById(R.id.image_button);
    mImageButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            pickImage();
        }
    });

    ParseFile imageFile = (ParseFile) ParseUser.getCurrentUser().get(NJUser.IMAGE_KEY);
    if (imageFile != null) {
        imageFile.getDataInBackground(new GetDataCallback() {

            @Override
            public void done(byte[] data, ParseException e) {
                InputStream is = new ByteArrayInputStream(data);
                Bitmap bmp = BitmapFactory.decodeStream(is);
                mImageButton.setImageBitmap(bmp);
            }
        });
    }

    return view;
}
    // touch logic and other stuff...
}

Solution

  • Turns out I was resetting the behind views and then changing the fragments after setting the SlideMenu object. After I changed the order of how things were set, bam, persistence and nothing being destroyed!