Android EditTextPreference - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android EditTextPreference class.

This code example shows how to use the following methods:getEditText
    preference = new EditTextPreference(context);
  } 
 
  @Test 
  public void testConstructor() { 
    preference = new EditTextPreference(context);
    assertNotNull(preference.getEditText());
  } 
 
  @Test 
  public void testSetText() { 
    preference.setText(SOME_TEXT);
    assertThat((String) preference.getEditText().getText().toString()).isEqualTo(SOME_TEXT);
  } 
 
} 
8
CodeRank
This code example shows how to use the following methods:setText, setSummary
        Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(cr,
                mProviderId, false /* keep updated */, null /* no handler */);
        String text;
 
        text = settings.getXmppResource();
        mXmppResource.setText(text);
        if (text != null) {
            mXmppResource.setSummary(text);
        } 
        text = Integer.toString(settings.getXmppResourcePrio());
        mXmppResourcePrio.setText(text);
        if (text != null) {
            mXmppResourcePrio.setSummary(text);
        } 
        text = Integer.toString(settings.getPort());
        mPort.setText(text);
        if (text != null && text != "5222" && text != "0") {
            mPort.setSummary(text);
        } 
        text = settings.getServer();
7
CodeRank
This code example shows how to use the following methods:getContext, getSharedPreferences, setEnabled, setSummary
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.layout.recentvideo_setting);
	 } 
	 
	@Override 
	public void onResume() { 
		super.onResume(); 
		final EditTextPreference pref = (EditTextPreference)findPreference("recentvideo_last_refresh");
		new RecentVideoRefreshPrefUpdater(pref);
	} 
} 

6
CodeRank
This code example shows how to use the following methods:setText, setDependency, setKey
	 */ 
	@SuppressWarnings("deprecation") 
	protected final EditTextPreference initTextPreference(String baseName, String defValue, String dependency) {
		// Update the loaded Preference with the actual preference key to load/store with 
		EditTextPreference pref = (EditTextPreference) findPreference(baseName);
		pref.setKey(baseName + "_" + key);
		pref.setDependency(dependency == null? null: dependency + "_" + key);
		// Update the Preference by loading the current stored value into the EditText, if it exists 
		pref.setText(sharedPrefs.getString(baseName + "_" + key, defValue));
		return pref;
	} 
 
	/** 
	 * Updates a preference that simply shows a check box. No default value will be shown. 
	 * @param baseName The base name of the stored preference, e.g. item_name, which will then actually be stored under 
	 *            item_name_[key] 
	 * @return The concrete {@link CheckBoxPreference} that is bound to this preference 
	 */ 
	protected final CheckBoxPreference initBooleanPreference(String baseName) {
		return initBooleanPreference(baseName, false);
7
CodeRank
This code example shows how to use the following methods:getEditText, getText, getOnPreferenceChangeListener, setOnPreferenceChangeListener, onPreferenceChange
public class MyPrefScreen extends PreferenceActivity {
	static final LogCategory log = new LogCategory("MyPrefScreen");
	 
	void initNumberEdit(String key,int min,int max,int def,int desc_string_id){
		EditTextPreference pref = (EditTextPreference)findPreference(key);
		EditText et = pref.getEditText();
		et.setHorizontallyScrolling(true);
		et.setSingleLine(true);
		et.setInputType(InputType.TYPE_CLASS_NUMBER);
 
		final int _min = min;
		final int _max = max;
		final int _def = def;
		final int _desc_string_id = desc_string_id;
		 
		pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
			@Override 
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				if(!MyApp.checkInteger(newValue,_min,_max)){
					Toast.makeText(MyPrefScreen.this,R.string.number_range_error,Toast.LENGTH_SHORT).show();

6
CodeRank
This code example shows how to use the following methods:getText
This code example shows how to use the following methods:getContext, getSharedPreferences, setEnabled, setSummary
		this.pref = pref;
		setValues(); 
	} 
 
	private void setValues() { 
		String timeAgoStr = pref.getSharedPreferences().getString("recentvideo_last_refresh", "0");
		String text = "";
		if(timeAgoStr == null || timeAgoStr.length() == 0)  {
			text = "Not yet";
		} 
		else { 
			long timeAgo = Long.valueOf(timeAgoStr);
			text = TimeAgo.toFriendlyString(pref.getContext(), timeAgo);
		} 
		 
		pref.setSummary(text);
		pref.setEnabled(false);
	} 
} 

6
CodeRank
This code example shows how to use the following methods:getText, setSummary
        super.onResume(); 
        updatePreferenceSummaries(); 
    } 
 
    private void updateSummary(EditTextPreference pref, String defaultText) {
        String value = pref.getText();
        if (value != null && value.length() > 0) {
            pref.setSummary(value);
        } else { 
            pref.setSummary(defaultText);
        } 
    } 
        
    private void updatePreferenceSummaries() { 
        updateSummary(urlPref, "URL to garage endpoint");
        updateSummary(ssidPref, "House wifi's SSID to look for");
    } 
 
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
6
CodeRank
This code example shows how to use the following methods:setText, setKey, setSummary, setTitle
		thumbnailEnable.setSummaryOff("Миниатюры НЕ отображаются");
		thumbnailEnable.setChecked(true);
 
		prefScreen.addPreference(thumbnailEnable);
 
		homeDir = new EditTextPreference(this);
 
		homeDir.setKey("home_dir");
		homeDir.setTitle("Домашняя папка");
		homeDir.setText(prefScreen.getSharedPreferences().getString("home_dir",
				"/sdcard")); 
		homeDir.setSummary("Эта папка будет отображаться при запуске приложения.Текущая папка "
				+ prefScreen.getSharedPreferences().getString("home_dir",
						"/sdcard")); 
		prefScreen.addPreference(homeDir);
 
	} 
 
	@Override 
	protected void onResume() { 
6
CodeRank
This code example shows how to use the following methods:setSummary
This code example shows how to use the following methods:setDialogTitle, setText, setKey, setSummary, setTitle
        SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME,  MODE_WORLD_WRITEABLE);
    	strSavedUsername = preferences.getString("master_username", null);
    	strSavedPassword = preferences.getString("master_password", null);
    	bolAutoLoggout = preferences.getBoolean("auto_loggout", true);
    	//set saved values 
    	editUsername.setText(strSavedUsername);
    	editPassword.setText(strSavedPassword);
    	autoLoggout.setChecked(bolAutoLoggout);    	
    } 
     
    private void SaveSettings() { 
    	if (autoLoggout.isChecked() == false) {
    		Toast.makeText(getBaseContext(), "Auto Close disabled. Please be sure to close vault when done or else the vault stays open.", Toast.LENGTH_LONG).show();
    	} 
    	 
    	//check for removing password 
    	if (removeLogin.isChecked() == false) {
    		try { //get data from form 
    			strSavedUsername = editUsername.getText().toString();
        	} catch (Exception e) {

6
CodeRank
This code example shows how to use the following methods:getText, setSummary
  } 
 
  private void updateUserText() { 
    EditTextPreference pref;
    pref = (EditTextPreference) findPreference("pref_username");
    String user = pref.getText();
 
    if (user == null) {
      user = "?";
    } 
 
    pref.setSummary(String.format("Username: %s", user));
  } 
} 
6
CodeRank
This code example shows how to use the following methods:setDialogTitle, getEditText, setDefaultValue, setKey, setSummary
This code example shows how to use the following methods:setDialogTitle, getEditText, setDefaultValue, setKey, setOnPreferenceChangeListener
This code example shows how to use the following methods:getEditText, setDefaultValue, setKey, setOnPreferenceChangeListener, setDialogTitle
This code example shows how to use the following methods:setDefaultValue, setKey, setSummary, setTitle
    // No menu options. 
  } 
 
  @Override 
  public void onSettingsMenu(PreferenceScreen screen, Context context) {
    EditTextPreference pref1 = new EditTextPreference(context);
    pref1.setSummary("Longitude server host:port");
    pref1.setKey("longitude_server");
    pref1.setTitle("Longitude server");
    pref1.setDefaultValue("");
    screen.addPreference(pref1);
    EditTextPreference pref2 = new EditTextPreference(context);
    pref2.setSummary("Longitude user");
    pref2.setKey("longitude_user");
    pref2.setTitle("Longitude user name");
    pref2.setDefaultValue("user");
    screen.addPreference(pref2);
    EditTextPreference pref3 = new EditTextPreference(context);
    pref3.setSummary("Longitude token");
    pref3.setKey("longitude_token");
6
CodeRank
This code example shows how to use the following methods:getEditText, setDefaultValue, setKey, setOnPreferenceChangeListener, setDialogTitle
This code example shows how to use the following methods:getEditText, setText
	private void setPreferenceValue(Method getter, Preference p) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		Object ret = getter.invoke(object, (Object[])null);
		if(ret != null) {
			if(p.getClass().equals(EditTextPreference.class)) {
				EditTextPreference etp = (EditTextPreference)p;
				etp.setText(ret.toString());
				if((etp.getEditText().getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == 0)
					updatePreferenceSummary(etp, ret.toString());
			} else if(p.getClass().equals(CheckBoxPreference.class)) {
				((CheckBoxPreference)p).setChecked((Boolean)ret);
			} else if(p.getClass().equals(ListPreference.class)) {
				ListPreference lp = (ListPreference)p;
				lp.setValue(ret.toString());
				updatePreferenceSummary(lp, ret.toString());
			} 
		} 
	} 
	 
	private void updatePrefs() { 
 
6
CodeRank
This code example shows how to use the following methods:getText, setSummary
This code example shows how to use the following methods:getText, setIntent, setOnPreferenceClickListener, setSummary
		super.onResume(); 
		// register pref change listener 
		getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
		 
		//TODO updatePreferences() containing following and others 
		pEtFolder.setSummary(pEtFolder.getText());
		setFolderPreferenceClickIntent(); 
		updateIntervalSummary(); 
		updateIntervalTypesEnabled(); 
		updatePTpDailyTime(); 
	} 
 
	// release the sharedPreferenceListener 
	@Override 
	protected void onPause() 
	{ 
		super.onPause(); 
		getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
	} 
	 

5
CodeRank
This code example shows how to use the following methods:setDialogTitle, getEditText, setDefaultValue, setDependency, setEnabled
		notificationPreferences.addPreference(notifyTime);
		notifyTime.setDependency(notifyEnabled.getKey());
		notifyTime.setEnabled(isSetTime);
		notifyTime.setSummary(formatSummary("notifytime",notifyTime.getTime()));
 
		EditTextPreference notifyInterval = new EditTextPreference(this);
		notifyInterval.setKey("notifyinterval");
		notifyInterval.setTitle("Notification Interval");
		notifyInterval.setDialogTitle("Notification Interval (in hours)");
		notifyInterval.setDefaultValue("24");
		notifyInterval.getEditText().setKeyListener(new NumberKeyListener() {
			@Override 
			protected char[] getAcceptedChars() { 
				char[] numberChars = {'1','2','3','4','5','6','7','8','9','0'};
				return numberChars;
			} 
 
			@Override 
			public int getInputType() { 
				return InputType.TYPE_NUMBER_FLAG_DECIMAL;

5
CodeRank
This code example shows how to use the following methods:setDialogTitle, getEditText, setKey, setTitle
This code example shows how to use the following methods:setSummary
This code example shows how to use the following methods:getText, setOnPreferenceChangeListener, setSummary
        addButtons(); 
    } 
 
    void bindLabelToValue (EditTextPreference preference)
    { 
        preference.setSummary(preference.getText());
        preference.setOnPreferenceChangeListener(
            new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference p, Object newValue) {
                    p.setSummary((String) newValue);
                    return true; 
                } 
            }); 
    } 
 
    // Based on code from the DeskClock app 
    void addButtons () 
    { 
        getListView().setItemsCanFocus(true);
 
6
CodeRank
This code example shows how to use the following methods:getText, setSummary
This code example shows how to use the following methods:getText, setSummary
This code example shows how to use the following methods:getText, setText, setSummary
		} 
		 
		if (key.endsWith("urlServidor")) {
			Preference pref = findPreference(key);
			EditTextPreference txt = (EditTextPreference) pref;
			if (txt.getText().length() > 0) {
				txt.setText("http://"+txt.getText().replace("http://", ""));
				txt.setSummary("http://"+txt.getText().replace("http://", ""));
			} 
		} 
		 
		if (key.endsWith("portaServidor")) {
			Preference pref = findPreference(key);
			EditTextPreference txt = (EditTextPreference) pref;
			if (txt.getText().length() > 0) {
				 
				txt.setSummary(txt.getText());
			 
			} 
		} 
5
CodeRank
This code example shows how to use the following methods:getEditText, getText, getSummary
This code example shows how to use the following methods:getEditText, getText, getSummary
This code example shows how to use the following methods:setText, setEnabled, setSummary

Related Android EditTextPreference Questions & Answers:

See Code Examples for Android EditTextPreference Methods: