Created
October 30, 2012 08:38
-
-
Save hvisser/3979027 to your computer and use it in GitHub Desktop.
Fixed TestListFragment that won't crash on hitting the back key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.neenbedankt.listfragmentbug; | |
import android.annotation.TargetApi; | |
import android.app.ListFragment; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.ArrayAdapter; | |
import android.widget.TextView; | |
public class TestListFragment extends ListFragment { | |
@Override | |
public void onViewCreated(View view, Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
TextView tv = new TextView(getActivity()); | |
tv.setText("Hello"); | |
getListView().addHeaderView(tv); | |
setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, | |
new String[] { "Hello world" })); | |
} | |
@Override | |
public void onDestroyView() { | |
super.onDestroyView(); | |
setListAdapter(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment