Android登录页面,数据库连接和用户名和密码检查。编辑文字设为点? [英] Android Login page, database connection and checking of username and password. Edit text set to dots?

查看:158
本文介绍了Android登录页面,数据库连接和用户名和密码检查。编辑文字设为点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修改了我之前的登录代码。

I've modified my previous code for login.

package log1.log2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Login extends Activity implements OnClickListener{

    UserDB db = new UserDB(this);
/** Called when the activity is first created. */

    private EditText etUsername;
    private EditText etPassword;
    private Button btnLogin;//private Button btnRegister;
    private TextView lblResult;

    @Override       
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
     // Get the EditText and Button References
        etUsername = (EditText)findViewById(R.id.usernametxt);
        etPassword = (EditText)findViewById(R.id.passwordtxt);
        btnLogin = (Button)findViewById(R.id.btnLogin);
        //btnRegister = (Button)findViewById(R.id.btnRegister);
        lblResult = (TextView)findViewById(R.id.msglbl);

        //Cursor c = (Cursor) db.getAllTitles();

        Button btnArrival = (Button) findViewById(R.id.btnRegister);
        btnArrival.setOnClickListener(this);

    // Set Click Listener
    btnLogin.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        db.open();
        // Check Login
        String username = etUsername.getText().toString();
        String password = etPassword.getText().toString();
        if(username.equals("")){
            if(password.equals(""))
                onClick();
            else
            {
                lblResult.setText("Wrong password");
            }       
        } else {
            lblResult.setText("Username does not exist. Please register.");
        }           
        db.close();
    }
  });
    }     
    public void onClick(View v)
    {   
        if (v.getId() == R.id.btnLogin) 
        {
            Intent intent = new Intent(this, Test.class);
            startActivity(intent);
        } 
        else
        {
            Intent intent = new Intent(this, Home.class);
            startActivity(intent);
        }               
     }       
}

我在我的if..else留下了一个空白。我不知道如何应用 sql 语句来检查用户和密码。

As you can see, I've left a blank on my if..else. I do not know how to apply an sql statement to check the user and password.

if(username.equals("sqlstatement")){
            if(password.equals("sqlstatement"))
                onClick();
            else
            {
                lblResult.setText("Wrong password");
            }    
 } else 
        lblResult.setText("Username does not exist. Please register.");

我插入 onClick 以指向其他方法,以便通过使用 onClickListener 方法(intent)将用户定向到另一个页面。但我有麻烦这样做,所以我认为我的代码是错误的,或者应该有另一种方法,直到用户输入正确的用户名和密码的其他页面。

I've insert onClick(); to direct to the other method so that the user will be directed to another page by using the onClickListener method, intent. But I'm having trouble doing that and so I thought that my code is wrong or there should be another way to direct to the other page once the user entered the correct username and password.

在此之前,我应该怎么做,以便有一个数据库连接?或者我通过插入 db.Open()创建了一个连接?

Before that, what should I do so that there would be a database connection? Or have I created a connection by inserting db.Open()?

我需要知道代码需要插入if..else语句。

I need to know the codes needed to be inserted the if..else statement.

我想知道是如何将密码上的文本 edittext 设置为点而不是实际文本。

Another basic stuff I want to know is how to set the text on the password edittext box to dots instead of the actual text.

推荐答案

重定向检查我的帖子在这个问题
http://android-pro.blogspot.com/2010/06/android-intents-part-2-passing-data-and.html

for redirection pleae check my post on this issue http://android-pro.blogspot.com/2010/06/android-intents-part-2-passing-data-and.html

并设置密码TextView,请检查此

and to set the password TextView please check this

http://android-pro.blogspot.com/2010/03/android-text-controls。 html

感谢

这篇关于Android登录页面,数据库连接和用户名和密码检查。编辑文字设为点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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