zoukankan      html  css  js  c++  java
  • 2.11

    今天主要是利用安卓studio写一个简单的注册界面

    package cn.edu.neusoft.fooddemo.activity;
    
    
    import android.content.Context;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import cn.edu.neusoft.fooddemo.R;
    import cn.edu.neusoft.fooddemo.util.Contants;
    
    public class LoginActivity extends BaseActivity {
    
        private EditText zhanghao;
        private EditText mima;
        private Button btn_login;
        private TextView btn_reg;
    
        protected void init(Context context){
            super.init(context);
            setContentView(R.layout.activity_login);
           btn_reg=(TextView)findViewById(R.id.register_btn);
            btn_login=(Button)findViewById(R.id.btn_login);
            zhanghao=(EditText)findViewById(R.id.login_name);
            mima=(EditText)findViewById(R.id.login_pass);
            btn_reg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(LoginActivity.this, RegisterActivity.class);
                    startActivity(intent);
                }
            });
            btn_login.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String username = zhanghao.getText().toString();
                    String password = mima.getText().toString();
                    //if (zhanghao.length() > 0 & mima.length() > 0) {
                    if(true){
                        String params = "?username=" + username + "&userpass=" + password;
                        getJSONByVolley(Contants.BASEURL + "userLogin.do" + params,null);
                    } else {
                        getToast("请输入账号密码");
                    }
                }
            });
        }
        @Override
        protected void setJSONDataToView(JSONObject response) {
            try {
                Log.e("=======================",response.toString());
               if("-1".equals(response.getString("userid")))
                    getToast("用户名和密码不能为空");
                else if(!"0".equals(response.getString("userid"))) {
                   Intent intent = new Intent();
                   intent.setClass(LoginActivity.this, MainActivity.class);
                   startActivity(intent);
                   LoginActivity.this.finish();
                   saveUser(response.getString("userid"));
               }
                   else
                   getToast("用户名和密码不能为空");
                }
            catch(JSONException e) {
            e.printStackTrace();
            }
        }
        public void saveUser(String user_id)
        {
            SharedPreferences sharedPreferences = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器
            editor.putString("username", zhanghao.getText().toString());
            int userid=Integer.parseInt(user_id);
            editor.putInt("user_id", userid);
            editor.putString("userpass",mima.getText().toString());
            editor.commit();//提交修改
        }
    }
  • 相关阅读:
    牛客练习赛51 D题
    Educational Codeforces Round 72 (Rated for Div. 2) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Educational Codeforces Round 72 (Rated for Div. 2) B题
    Educational Codeforces Round 72 (Rated for Div. 2) A题
    《DSP using MATLAB》Problem 7.2
    《DSP using MATLAB》Problem 7.1
    《DSP using MATLAB》Problem 6.24
  • 原文地址:https://www.cnblogs.com/ljpljm/p/12297438.html
Copyright © 2011-2022 走看看