android - addPreferencesFromResource -


i know might duplicate from: what use instead of "addpreferencesfromresource" in preferenceactivity?

but still can not code work , appreciate help. can not the: "addpreferencesfromresource(r.xml.preferences);" work.

preferences not resolved, though in r.xml folder.

i followed example in above link letter.

please help!!

package com.example.oasisreference;  import android.r; import android.r.xml; //import android.annotation.targetapi; import android.os.bundle; import android.preference.preferenceactivity; import android.preference.preferencefragment;  public class prefs extends preferenceactivity  {  @override protected void oncreate(final bundle savedinstancestate) {     // todo auto-generated method stub     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.preferences); }  }  } 

preferences.xml in res.xml folder

<?xml version="1.0" encoding="utf-8"?> <preferencescreen  xmlns:android="http://schemas.android.com/apk/res/android" >  <edittextpreference     android:title="user name"     android:key="name"     android:summary="enter name"     ></edittextpreference> <checkboxpreference     android:title="euro currency"     android:defaultvalue="false"     android:key="euro"     android:summary="check use cost calculator in euros/liters">  </checkboxpreference>   </preferencescreen> 

menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >   <item     android:id="@+id/aboutus"     android:title="about author"> </item> <item     android:id="@+id/preferences"     android:title="preferences"> </item> <item      android:id="@+id/exit"     android:title="exit"> </item>  </menu> 

delete import android.r work


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -