Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 检索时登录时出错_Android_Sqlite - Fatal编程技术网

Android 检索时登录时出错

Android 检索时登录时出错,android,sqlite,Android,Sqlite,我有一个包含四个edittext的主屏幕。在每个edittext中,我只接受一位数的值。我在每个edittext上设置requestFocus()。一旦我在forth edittext中输入值,它应该调用构造函数,启动一个查询并返回我登录是否成功。相反,它给我的消息是“登录失败” 这是我的密码 edit4.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int arg

我有一个包含四个edittext的主屏幕。在每个edittext中,我只接受一位数的值。我在每个edittext上设置requestFocus()。一旦我在forth edittext中输入值,它应该调用构造函数,启动一个查询并返回我登录是否成功。相反,它给我的消息是“登录失败”

这是我的密码

edit4.setOnKeyListener(new OnKeyListener() {
    @Override
    public boolean onKey(View arg0, int arg1, KeyEvent arg2) 
    {
        // TODO Auto-generated method stub
        if(edit4.getText().toString().length()==1)
        {
            ParentDBHelper helper = new ParentDBHelper(getApplicationContext(), "db_parents", null, 2);
            SQLiteDatabase db=helper.getWritableDatabase();
            Cursor c=db.rawQuery("SELECT * FROM tbl_countries", null);
            // check if the table is empty 
            if (!c.moveToNext())
            {
                Toast.makeText(getApplicationContext(), "No data to display, please make sure you have already inserted data!", Toast.LENGTH_LONG).show();
                db.close();
                return false;
            }
            c.moveToPrevious();
            // if the table is not empty, read the result into a string named display 
            while(c.moveToNext())
            {
                String 
                String no1=c.getColumnName(5); 
                if(no1==edit1.getText().toString()+edit2.getText().toString()+edit3.getText().toString()+edit4.getText().toString())
                {
                    flag_status_pin=1;
                    Toast.makeText(getApplicationContext(), "Login Successful!!", Toast.LENGTH_LONG).show();
                    Intent dash1=new Intent(getApplicationContext(),DashBoard.class);
                    startActivity(dash1);
                }
            }
            if(flag_status_pin==0)
            {
                Toast.makeText(getApplicationContext(), "Login Failed!!", Toast.LENGTH_LONG).show();
                Intent homes=new Intent(getApplicationContext(),home.class);
                startActivity(homes);
            }  

        }//if 

        return false;
    }}); 

谢谢。

在编辑文本时使用文本观察程序比使用键盘监听器更好:

TextWatcher watcher = new TextWatcher(){

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    //Test here for login
}


然后将其设置为
edit4.addTextChangedListener(watcher)
您需要稍微更改您的逻辑。

您正在使用
==
比较字符串。这是行不通的。使用equals代替

此外,您正在将pin码与列名进行比较?难道你不应该把它和

c.getString(5)

相反?

@swand:onCreate()可以。如果遇到任何问题,您可以发布更新后的代码。谢谢。但它不会进入我触发查询的循环。相反,它总是显示“登录失败”。我不确定在调用moveToNext超过光标限制后您是否可以返回。我将用单个if-moveToFirst[…]else返回替换if和while以及moveToPrevious
c.getString(5)