如何显示包含用户名的欢迎回复消息

时间:2015-10-27 10:05:21

标签: android android-layout ui-design gui-design

这是我想要做的,我有一个带有用户名和密码的android登录表单,在用户输入他的凭据并登录后,下一个表单应显示在页面顶部欢迎,+用户名从登录页面输入!但如果用户重新访问我的应用程序,那么该消息应该是欢迎回用户名,以及我如何知道用户已经在我的应用程序中再次访问过?,有人可以帮助我吗?

我是Android开发的新手,并且不知道如何解决这个问题。谢谢 公共类HomeScreen扩展Activity实现OnClickListener {     String response = null;

public static HomeScreen object = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    object = this;
    // String type = getResources().getString(R.string.TYPE);
    // Logger.logger("mobile type :::::::::::: " + type);
    // if (type.equalsIgnoreCase("mobile")) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    // }
    setContentView(R.layout.home);

    findViewById(R.id.btn_call_us).setOnClickListener(this);
    findViewById(R.id.btn_email_us).setOnClickListener(this);
    findViewById(R.id.btn_panel_book).setOnClickListener(this);
    findViewById(R.id.btn_get_instant_quote).setOnClickListener(this);
    findViewById(R.id.btn_logout).setOnClickListener(this);
    ((TextView) findViewById(R.id.tv_welcome_msg_title)).setText("Welcome "
            + Comman.getPreference(HomeScreen.this, AppConstants.PRE_F_NAME, "") + "!");

    new getJustInData().execute();
}

字符串响应;

    @Override
    protected String doInBackground(String... params) {
        try {
            response = HttpProcess.postDataOnServer(AppConstants.URL_WELCOME + "client="
                    + Comman.getPreference(HomeScreen.this, AppConstants.PRE_COMPANY_NAME, ""));
            Logger.logger("respons in welcome Message : " + response);
        } catch (Exception e) {
            response = "";
        }
        return "";
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        PDialog.dismiss();
        String msg = Comman.getPreference(HomeScreen.this, AppConstants.PRE_WELCOME, "");

        try {
            String WelComeMsgResponseList = JsonParser.readWelcomeResponse(response);
            if (WelComeMsgResponseList != null && WelComeMsgResponseList.length() > 0) {
                Comman.setPreference(HomeScreen.this, AppConstants.PRE_WELCOME, WelComeMsgResponseList);
                ((WebView) findViewById(R.id.webview)).loadData("<font style='color:#ffffff;'><MARQUEE> "
                        + WelComeMsgResponseList + "  </MARQUEE></font>", "text/html", null);
                ((WebView) findViewById(R.id.webview)).setBackgroundColor(Color.BLACK);
                return;
            }
        } catch (Exception e) {
        } catch (Error e) {
        }
        ((WebView) findViewById(R.id.webview)).loadData("<font style='color:#ffffff;'><MARQUEE> " + msg
                + " </MARQUEE></font>", "text/html", null);
        ((WebView) findViewById(R.id.webview)).setBackgroundColor(Color.BLACK);
    }

}

}

2 个答案:

答案 0 :(得分:1)

将数据保存在ShreadPreference中并使用您的逻辑处理。

答案 1 :(得分:0)

用户名的Useshared首选项,还存储登录状态。 例如 - &gt;启动应用程序时检查用户登录状态,如果为真,则在活动顶部显示用户名,否则重定向到登录页面。

private static final String PREFER_NAME = "";

private static final String IS_USER_LOGIN = "";

public static final String KEY_NAME = "";

public static final String KEY_Password = "";
SharedPreferences pref;
SharedPreferences.Editor editor;
在create方法中

放下这些行:

    pref = context.getSharedPreferences(PREFER_NAME, PRIVATE_MODE);
    editor = pref.edit();

    editor.putBoolean(IS_USER_LOGIN, true);

    editor.putString(KEY_NAME, name);

    editor.putString(KEY_Password, password);

    editor.commit();

检查用户是否已登录:

public boolean isUserLoggedIn() {

    return pref.getBoolean(IS_USER_LOGIN, false);
}
相关问题