[알림] addPreferencesFromResource 줄 처져 있을 때

반응형

기존이 아래와 같은 방식이라면

public class MyPreferenceActivity extends PreferenceActivity

{

    @Override

    protected void onCreate(final Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.my_preference_screen);

    }

}

 

이렇게 바꾸어 사용이 가능하다.

 

public class MyPreferenceActivity extends PreferenceActivity

{

    @Override

    protected void onCreate(final Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();

    }

    public static class MyPreferenceFragment extends PreferenceFragment

    {

        @Override

        public void onCreate(final Bundle savedInstanceState)

        {

            super.onCreate(savedInstanceState);

            addPreferencesFromResource(R.xml.my_preference_screen);

        }

    }

}

 

* 파란 표시는 바뀌는 부분. 놓치지 않도록 주의

 

 

[출처] https://stackoverflow.com/questions/6822319/what-to-use-instead-of-addpreferencesfromresource-in-a-preferenceactivity/6822461#6822461

반응형

댓글()