开发者

Pragmatic Hello Android, Inflating seetings from XML to view in current activity

I am using method addPreferenceFromResources() to read the settings definition from XML file and inflate them into views in the current activity. but it is giving me an error and saying that this method is deprecated in Android now. Please help me to learn a new method to perform this task.

Code:

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class prefs extends PreferenceActivity{
    @Override
    protected void onCreate(Bundle savedInst开发者_如何学JAVAanceState){
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
    }

}

Thanks, Varun


I believe you start using sdk 3.0. They somehow changed the way to present preferences screen with new fragments feature. If you're not targeting tablets with your app, then old addPreferencesFromResource still works.

If you want to target tablets, then as the doc says(http://developer.android.com/reference/android/preference/PreferenceActivity.html) take a look at PreferenceFragment class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜