+ Reply to Thread
Results 1 to 2 of 2

Thread: How to use EditTextPreference?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    15

    How to use EditTextPreference?

    Recently i have got to know that they is something know as EditTextPreference in Android which will be helpfull to save settings.But unable to figure out how to use it.Just a little help to get started

  2. #2
    This preference allows you to capture raw text rather than ask the user to make a selection.To demonstrate this, let’s assume you have an application that generates Java code for the user. One of the preference settings of this application might be the default package name to use for the generated classes. So here, you want to display a text field to the user and allow her to set the package name for the generated classes

    packagepref.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="package_name_screen"
    android:title="Package Name"
    android:summary="Set package name">
    <EditTextPreference
    android:key="package_name_preference"
    android:title="Set Package Name"
    android:summary="Set the package name for generated code"
    android:dialogTitle="Package Name" />
    </PreferenceScreen>
    EditTextPreferenceActivity.java
    Code:
    import android.os.Bundle;
    import android.preference.PreferenceActivity;
    
    public class EditTextPreferenceActivity extends PreferenceActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.packagepref);
    }
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts