无法将这个登录页面注册页面转换 [英] Unable to convert this login page to signup page

查看:170
本文介绍了无法将这个登录页面注册页面转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是登录页面在我的应用程序,现在我想创建注册页面。我认为它容易使在登录类的变化作出新的注册类。我已经尝试了很多,但无力。而我之所以想从本作的注册页面是,在登录类,我有我的远程服务器连接成功。注册类我想重新输入密码和手机2个编辑的文本字段。此外,在登录类,你看,我有复选框,但注册类我不想复选框。因此,其对我来说很难将其转换。如果有人愿意帮助我。请尝试。

LoginActivity类 -

 公共类LoginActivity延伸活动{    我的意图;
    按钮登入,注册;
    TextView的错误;
    复选框检查;
    字符串名称=,通=;
    字节[]数据;
    HttpPost httppost;
    StringBuffer的缓冲区;
    HTT presponse响应;
    HttpClient的HttpClient的;
    InputStream的InputStream的;
    共享preferences APP_ preferences;
    清单<&的NameValuePair GT; namevaluepairs中;
    的EditText editTextId,editTextP;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.login);
        登入=(按钮)findViewById(R.id.signin);
        editTextId =(EditText上)findViewById(R.id.editTextId);
        editTextP =(EditText上)findViewById(R.id.editTextP);
        APP_ preferences = preferenceManager.getDefaultShared preferences(本);
        检查=(复选框)findViewById(R.id.check);
        字符串Str_user = APP_ preferences.getString(用户名,0);
        字符串Str_pass = APP_ preferences.getString(密码,0);
        字符串Str_check = APP_ preferences.getString(选中,无);
        如果(Str_check.equals(是)){
            editTextId.setText(Str_user);
            editTextP.setText(Str_pass);
            check.setChecked(真);
        }        signin.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                名称= editTextId.getText()的toString()。
                通过= editTextP.getText()的toString()。
                字符串Str_check2 = APP_ preferences.getString(选中,无);
                如果(Str_check2.equals(是)){
                    共享preferences.Editor编辑= APP_ preferences.edit();
                    editor.putString(用户名,名);
                    editor.putString(密码,通过);
                    editor.commit();
                }
                如果(name.equals()|| pass.equals()){
                    Toast.makeText(LoginActivity.this,空白Field..Please回车,Toast.LENGTH_SHORT).show();
                }其他{
                    新LoginTask()执行();
                }
            }
        });
        check.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                //在点击执行操作,取决于它是否现在
                //检查
                共享preferences.Editor编辑= APP_ preferences.edit();
                如果(((复选框)ⅴ).isChecked()){
                    editor.putString(选中,是);
                    editor.commit();
                }其他{
                    editor.putString(选中,无);
                    editor.commit();
                }
            }
        });
    }    公共无效Move_to_next()
    {
        startActivity(新意图(LoginActivity.this,SplashActivity.class));
        完();
    }
    @燮pressLint(NewApi)
    私有类LoginTask扩展的AsyncTask<太虚,太虚,字符串>
    {
        @燮pressLint(NewApi)
        @覆盖
        在preExecute保护无效()
        {            super.on preExecute();
            //显示进度对话框这里
        }        @覆盖
        保护字符串doInBackground(虚空......为arg0){
            尝试{
                HttpClient的=新DefaultHttpClient();
                httppost =新HttpPost(http://abc.com/login1.php);
                //添加数据
                namevaluepairs中=新的ArrayList<&的NameValuePair GT;(2);
                nameValuePairs.add(新BasicNameValuePair(USEREMAIL,name.trim()));
                nameValuePairs.add(新BasicNameValuePair(密码,pass.trim()));
                httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));
                //执行HTTP POST请求
                响应= httpclient.execute(httppost);
                的InputStream = response.getEntity()的getContent()。
                数据=新的字节[256];
                缓冲区=新的StringBuffer();
                INT LEN = 0;
                而(-1!=(LEN = inputStream.read(数据))){
                    buffer.append(新的String(数据,0,LEN));
                }                inputStream.close();
                返回buffer.toString();
            }
            赶上(例外五)
            {
                e.printStackTrace();            }
            返回;
        }        @燮pressLint(NewApi)
        @覆盖
        保护无效onPostExecute(字符串结果){
            super.onPostExecute(结果);
            //隐藏进度对话框这里            如果(buffer.charAt(0)=='Y'){
                Toast.makeText(LoginActivity.this,登录全成,Toast.LENGTH_SHORT).show();
                Move_to_next();
            }其他{
                Toast.makeText(LoginActivity.this,无效的用户名或密码,Toast.LENGTH_SHORT).show();
            }
        }
    }
}


解决方案

您需要设置的知名度,走了/可见/可见改变复选框和其他项目的可见性,以适合您的要求。

This is login page in my app and now i want to create sign up page. I think its easy to make changes in the login class to make new signup class. I have tried a lot but unable. And reason why i want to make signup page from this is that in login class i have successful connection with my remote server. In sign up class i want 2 more edit text field for re-type password and mobile. Also in login class as you see i have check box but in sign up class i do not want check box. Therefore its difficult for me to convert it. If someone like to help me. Please try.

LoginActivity Class-

public class LoginActivity extends Activity {

    Intent i;
    Button signin, signup;
    TextView error;
    CheckBox check;
    String name = "", pass = "";
    byte[] data;
    HttpPost httppost;
    StringBuffer buffer;
    HttpResponse response;
    HttpClient httpclient;
    InputStream inputStream;
    SharedPreferences app_preferences;
    List<NameValuePair> nameValuePairs;
    EditText editTextId, editTextP;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        signin = (Button) findViewById(R.id.signin);
        editTextId = (EditText) findViewById(R.id.editTextId);
        editTextP = (EditText) findViewById(R.id.editTextP);
        app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
        check = (CheckBox) findViewById(R.id.check);
        String Str_user = app_preferences.getString("username", "0");
        String Str_pass = app_preferences.getString("password", "0");
        String Str_check = app_preferences.getString("checked", "no");
        if (Str_check.equals("yes")) {
            editTextId.setText(Str_user);
            editTextP.setText(Str_pass);
            check.setChecked(true);
        }

        signin.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                name = editTextId.getText().toString();
                pass = editTextP.getText().toString();
                String Str_check2 = app_preferences.getString("checked", "no");
                if (Str_check2.equals("yes")) {
                    SharedPreferences.Editor editor = app_preferences.edit();
                    editor.putString("username", name);
                    editor.putString("password", pass);
                    editor.commit();
                }
                if (name.equals("") || pass.equals("")) {
                    Toast.makeText(LoginActivity.this, "Blank Field..Please Enter", Toast.LENGTH_SHORT).show();
                } else {
                    new LoginTask().execute();
                }
            }
        });


        check.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks, depending on whether it's now
                // checked
                SharedPreferences.Editor editor = app_preferences.edit();
                if (((CheckBox) v).isChecked()) {
                    editor.putString("checked", "yes");
                    editor.commit();
                } else {
                    editor.putString("checked", "no");
                    editor.commit();
                }
            }
        });
    }

    public void Move_to_next() 
    {
        startActivity(new Intent(LoginActivity.this, SplashActivity.class));
        finish();
    }


    @SuppressLint("NewApi")
    private class LoginTask extends AsyncTask <Void, Void, String> 
    {
        @SuppressLint("NewApi")
        @Override
        protected void onPreExecute() 
        {

            super.onPreExecute();
            // Show progress dialog here
        }

        @Override
        protected String doInBackground(Void... arg0) {
            try {
                httpclient = new DefaultHttpClient();
                httppost = new HttpPost("http://abc.com/login1.php");
                // Add your data
                nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
                nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                // Execute HTTP Post Request
                response = httpclient.execute(httppost);
                inputStream = response.getEntity().getContent();
                data = new byte[256];
                buffer = new StringBuffer();
                int len = 0;
                while (-1 != (len = inputStream.read(data))) {
                    buffer.append(new String(data, 0, len));
                }

                inputStream.close();
                return buffer.toString();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();

            }
            return "";
        }

        @SuppressLint("NewApi")
        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            // Hide progress dialog here

            if (buffer.charAt(0) == 'Y') {
                Toast.makeText(LoginActivity.this, "login successfull", Toast.LENGTH_SHORT).show();
                Move_to_next();
            } else {
                Toast.makeText(LoginActivity.this, "Invalid Username or password", Toast.LENGTH_SHORT).show();
            }
        }
    }
}

解决方案

You need to set the visibility to gone/invisible/visible to change the visibility of check box and other items to suite your requirements.

这篇关于无法将这个登录页面注册页面转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆