Using Preferences

Put your problem here if it does not fit any of the other categories.

Using Preferences

Postby travisjames » Wed Apr 08, 2009 9:32 pm

I am using this method to access my preferences.xml file and use the preference I obtain:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Button update = (Button) findViewById(R.id.update);
  2.  
  3.         update.setOnClickListener(new Button.OnClickListener() {
  4.  
  5.                 public void onClick(View v) {
  6.  
  7.                         EditText status = (EditText) findViewById(R.id.status);
  8.  
  9.                         String updtext = status.getText().toString();
  10.  
  11.                        
  12.  
  13.                         SharedPreferences settings = TwitterIt.this.getSharedPreferences
  14.  
  15.                         ("com.travisjames.twitterit_preferences", 0);
  16.  
  17.                         String value = settings.getString("user", "defaultvalue");
  18.  
  19.                         String value2 = settings.getString("pass", "defaultvalue");
  20.  
  21.                        
  22.  
  23.                         Twitter twitter = new Twitter(value,value2);
  24.  
  25.                         twitter.setSource("twitterit");
  26.  
  27.                         twitter.updateStatus(updtext);
  28.  
  29.                         status.setText("");
  30.  
  31.                 }
  32.  
  33.         });
  34.  
  35.     }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


and this is my preferences.xml file:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <PreferenceScreen
  2.  
  3.         xmlns:android="http://schemas.android.com/apk/res/android">
  4.  
  5.         <PreferenceCategory android:title="Twitter Credentials">
  6.  
  7.         <EditTextPreference
  8.  
  9.                 android:key="user"
  10.  
  11.                 android:title="Username"
  12.  
  13.                 android:summary="Your Twitter.com username" />
  14.  
  15.         <EditTextPreference
  16.  
  17.                 android:key="pass"
  18.  
  19.                 android:title="Password"
  20.  
  21.                 android:summary="Your Twitter.com password" />
  22.  
  23.                 </PreferenceCategory>
  24.  
  25. </PreferenceScreen>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


But for some reason, both value strings keep returning "defualtvalue" even though android:key is defined for both values in my preferences.xml file.

Any help about how I should do this?
travisjames
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 02, 2009 10:00 pm
Location: Cordova, Tennessee

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests