0

iam using two buttons one is for select another is not selected if i click on select img the username have to be display after logout

android

<ImageView
        android:id="@+id/log_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
           android:visibility="gone"
        android:src="@drawable/tickmark"
        android:layout_marginRight="@dimen/remember_margin_right"
        android:layout_marginBottom="@dimen/margin_bottom_remember"/>


           <ImageView
               android:id="@+id/log_img_unselect"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_toLeftOf="@+id/text_remember"
               android:src="@drawable/unselect"
               android:layout_marginRight="@dimen/remember_margin_right"
               android:layout_marginBottom="@dimen/margin_bottom_remember"/>
v teja
  • 613
  • 2
  • 7
  • 17
  • In order to help, please add some code, especially the code behind the buttons you are using. – Strider Feb 16 '16 at 10:37
  • to save the state , you need some persistence storage, [SharedPreferences](http://stackoverflow.com/questions/3851560/how-to-use-sharedpreferences) is what you are looking for. – nobalG Feb 16 '16 at 10:41

1 Answers1

0

You can use SharedPreferences to keep username, without database. And when you click on logout button, call login screen again and read username from Preferences. An example code below:

public static final String MyPREFERENCES = "MyPrefs";
public static final String USERNAME_KEY = "counter";

public static String getUsername(Context context) {
        SharedPreferences prefs = context.getSharedPreferences(MyPREFERENCES, context.MODE_PRIVATE);
        return prefs.getString(USERNAME_KEY, null);
    }

public static void setUserEmailToPreference(Context context, String username) {

    SharedPreferences.Editor editor = context.getSharedPreferences(MyPREFERENCES, context.MODE_PRIVATE).edit();
    editor.putString(USERNAME_KEY, username);
    editor.commit();
}

Now you only need to call these methods. Best regards. Uilton.

uiltonsantos
  • 409
  • 4
  • 9