Answer :
- think about the MENU_SETUP of the onOptionsItemSelected method (override)
- from there, start a specialized PreferenceActivity
Details :
Step #1 : MENU_SETUP press handling :
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case MENU_SETUP:
showPreferences();
break;
default:
break;
}
return true;
}
Step #2 : an Android intent allows to start a to-be-specialized PreferenceActivity, named here : Prefs
/**
* Dialog box display of the preferences setting window
*/
private void showPreferences()
{
Intent prefs = null; // Preferences activity display intent
prefs = new Intent(getApplicationContext(), Prefs.class);
startActivity(prefs);
}
Step #3 : specialized Prefs class body
The 'R.layout.prefs' being given by a './res/layout/Prefs.xml' resource file ; here is such a resource contents in case just 2 edit text components are needed :
public final class Prefs extends PreferenceActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
// Setting activity content
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.prefs);
}
}
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="Preferences">
<EditTextPreference
// ...
/>
<EditTextPreference
// ...
/>
</PreferenceScreen>
Step #4 : finally, add this entry into the AndroidManifest.xml :
<activity android:name=".Prefs" android:label="Configuration"/>





No comments:
Post a Comment