Using Preferences to login?

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

Using Preferences to login?

Postby songotho » Wed Apr 22, 2009 7:27 pm

Hi,
I want to use Preferences to get data in EditText to login my app. So I can get data in EditText but I can't compare the data of EditText in file Login and in file Preferences. Would you tell me how I can do?
Preferences file :
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  3.         <PreferenceCategory android:title="UserName">
  4.                 <EditTextPreference
  5.                         android:key="cusername"
  6.                         android:title="Change UserName"
  7.                         android:summary="Click to pop up a field for entry"
  8.                         android:dialogTitle="Enter new User"/>
  9.         </PreferenceCategory>
  10.         <PreferenceCategory android:title="Password">
  11.                 <EditTextPreference
  12.                         android:key="cpassword"
  13.                         android:title="Change Password"
  14.                         android:summary="Click to pop up a field for entry"
  15.                         android:password="true"
  16.                         android:dialogTitle="Enter new Password"/>
  17.         </PreferenceCategory>
  18. </PreferenceScreen>
  19.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

Java:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.os.Bundle;
  2. import android.preference.PreferenceActivity;
  3.  
  4. public class ChangeUser extends PreferenceActivity {
  5.         @Override
  6.          protected void onCreate(Bundle savedInstanceState) {
  7.                  super.onCreate(savedInstanceState);           
  8.                  addPreferencesFromResource(R.xml.changeuser);
  9.         }
  10. }
  11.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


This is my Login file:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Login extends Activity  {
  2.         private TextView tempUser;
  3.         private TextView tempPass;
  4.        
  5.         private EditText eUser;
  6.         private EditText ePass;
  7.         private Button mLog;
  8.         private Button mClose;
  9.  public void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         setContentView(R.layout.login);
  12.  
  13.         eUser = (EditText) findViewById(R.id.username);
  14.         ePass = (EditText) findViewById(R.id.password);
  15.        
  16.         SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  17.         tempUser.setText(prefs.getString("cusername", ""));
  18.         tempPass.setText(prefs.getString("cpassword", ""));
  19.        
  20.         mLog = (Button) findViewById(R.id.loginbutton);
  21.         mLog.setOnClickListener (mLogListener);
  22.         mClose = (Button) findViewById(R.id.closebutton);
  23.         mClose.setOnClickListener (mCloListener);
  24. }
  25.  private OnClickListener mLogListener = new OnClickListener() {        
  26.         public void onClick(View v) {
  27.                
  28.         }
  29.     };
  30.    
  31.     private OnClickListener mCloListener = new OnClickListener() {
  32.         public void onClick(View v) {
  33.                 finish();
  34.         }
  35.     };
  36. }
  37.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

Login.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.         android:layout_width="fill_parent"
  4.        android:layout_height="fill_parent">
  5. <ScrollView
  6.         android:layout_width="fill_parent"
  7.        android:layout_height="fill_parent">
  8. <LinearLayout
  9.    android:layout_width="fill_parent"
  10.    android:layout_height="fill_parent"
  11.    android:orientation="vertical"
  12.    android:scrollbars="vertical">
  13.         <TextView
  14.                 android:layout_width="fill_parent"
  15.                 android:layout_height="wrap_content"
  16.                 android:layout_gravity="center_vertical|center_horizontal|center"/>
  17.         <TextView  
  18.             android:id="@+id/logintext"
  19.             android:layout_height="wrap_content"
  20.             android:text="TEST"
  21.                 android:textStyle="bold"
  22.                 android:textSize="20px" android:layout_gravity="center" android:layout_width="fill_parent"/>
  23.         <TextView
  24.                 android:layout_width="fill_parent"
  25.                 android:layout_height="20px"
  26.                 android:layout_gravity="center_vertical|center_horizontal|center"/>
  27.         <TextView
  28.             android:id="@+id/usertext"
  29.             android:layout_width="fill_parent"
  30.             android:layout_height="wrap_content"
  31.             android:layout_gravity="center_vertical|center_horizontal|center"
  32.             android:text="USERNAME"/>
  33.     <EditText
  34.             android:id="@+id/username"
  35.             android:layout_height="wrap_content"
  36.                 android:focusableInTouchMode="true"
  37.                 android:layout_gravity="center_horizontal"
  38.                 android:layout_marginRight="5dip"
  39.                 android:layout_marginLeft="5dip"
  40.                 android:layout_width="320dip" android:singleLine="true" android:focusable="true"/>
  41.         <TextView
  42.                 android:layout_width="fill_parent"
  43.                 android:layout_height="10px"
  44.                 android:layout_gravity="center_vertical|center_horizontal|center"/>
  45.         <TextView
  46.             android:id="@+id/passtext"
  47.             android:text="PASSWORD"
  48.             android:layout_width="fill_parent"
  49.             android:layout_height="wrap_content"
  50.             android:layout_gravity="center_vertical|center_horizontal|center"/>
  51.     <EditText
  52.             android:id="@+id/password"
  53.             android:layout_height="wrap_content"
  54.                 android:focusableInTouchMode="true"
  55.                 android:layout_gravity="center_horizontal"
  56.                 android:layout_marginRight="5px"
  57.                 android:layout_marginLeft="5dip"
  58.                 android:layout_width="320dip"
  59.                 android:password="true" android:singleLine="true"/>
  60.         <TextView
  61.                 android:layout_width="fill_parent"
  62.                 android:layout_height="30px"
  63.                 android:layout_gravity="center_vertical|center_horizontal|center"/>    
  64. <LinearLayout
  65.         android:orientation="horizontal"
  66.    android:layout_height="wrap_content"
  67.    android:layout_gravity="center"
  68.    android:layout_width="wrap_content">
  69.         <Button
  70.             android:id="@+id/loginbutton"
  71.             android:layout_height="50dip"
  72.                 android:text="LOGIN"
  73.                 android:layout_width="103dip"/>
  74.         <Button
  75.                 android:id="@+id/closebutton"
  76.                 android:layout_height="50dip"
  77.                 android:text="CLOSE"
  78.                 android:layout_width="103dip"/>
  79. </LinearLayout>
  80.         <TextView
  81.                 android:layout_width="fill_parent"
  82.                 android:layout_height="30px"
  83.                 android:layout_gravity="center_vertical|center_horizontal|center"/>    
  84. </LinearLayout>
  85. </ScrollView>
  86. </RelativeLayout>
  87.  
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Thanks,

--Alex
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 15 guests