Code example for ListFragment

Methods: getActivity, onCreate

0
            */ 
    } 
 
    @Override 
    public void onCreate(Bundle b) {
        super.onCreate(b);
        mPreferenceManager = onCreatePreferenceManager();    
    } 
     
    @Override 
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
 
		lv = getListView();
        lv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);                	
        setListShown(true);
 
        PreferenceScreen screen = createPreferenceHierarchy(mPreferenceManager);
        if (screen != null) setPreferenceScreen(screen);
        postBindPreferences(); 
         
    	//((OnPreferenceAttachedListener)getActivity()).onPreferenceAttached(getPreferenceScreen(), 0); 
	} 
     
	protected abstract PreferenceScreen createPreferenceHierarchy(PreferenceManager prefMan);
 
    @Override 
    public void onStop(){ 
        super.onStop(); 
        try{ 
            Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityStop");
            m.setAccessible(true);
            m.invoke(mPreferenceManager);
        }catch(Exception e){
            e.printStackTrace();
        } 
    } 
 
    @Override 
    public void onDestroy() { 
        super.onDestroy(); 
        lv = null;
        try{ 
            Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityDestroy");
            m.setAccessible(true);
            m.invoke(mPreferenceManager);
        }catch(Exception e){
            e.printStackTrace();
        } 
    } 
 
    @Override 
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt("xml", xmlId);
        super.onSaveInstanceState(outState);
 
    } 
 
    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try{ 
            Method m = PreferenceManager.class.getDeclaredMethod("dispatchActivityResult", int.class, int.class, Intent.class);
            m.setAccessible(true);
            m.invoke(mPreferenceManager, requestCode, resultCode, data);
        }catch(Exception e){
            e.printStackTrace();
        } 
    } 
 
    /** 
     * Posts a message to bind the preferences to the list view. 
     * <p> 
     * Binding late is preferred as any custom preference types created in 
     * {@link #onCreate(Bundle)} are able to have their views recycled. 
     */ 
    private void postBindPreferences() { 
        if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) return;
        mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget();
    } 
     
    private void bindPreferences() { 
        final PreferenceScreen preferenceScreen = getPreferenceScreen();
        if (preferenceScreen != null) {
        	try { 
        		if (lv == null) lv = getListView();
        		preferenceScreen.bind(lv);
        	} catch (Exception e) {        		
        	} 
        } 
    } 
     
    /** 
     * Creates the {@link PreferenceManager}. 
     *  
     * @return The {@link PreferenceManager} used by this activity. 
     */ 
    private PreferenceManager onCreatePreferenceManager() {
        try{ 
            Constructor<PreferenceManager> c = PreferenceManager.class.getDeclaredConstructor(Activity.class, int.class);
            c.setAccessible(true);
            PreferenceManager preferenceManager = c.newInstance(this.getActivity(), FIRST_REQUEST_CODE);
            return preferenceManager;
        }catch(Exception e){
            e.printStackTrace();
            return null; 
        } 
Experience pair programming with AI  Get Codota for Java