vendredi 27 novembre 2015

how to get the cursor data which is appended to another activity and split the appended data to get the Id of that row

I have a database where i have Unique id, Email id and Password. Im storing using SQlite database. I've to get the cursor which stores the result of the query, i have got the cloumn index of each cloumn, appended it using StringBuffer, but i dont know how to get those values in the other class? please help. here is my code for Adapter class:

public String getData(String email,String pwd)
{
    StringBuffer buffer=new StringBuffer();
    SQLiteDatabase db =sciHelper.getWritableDatabase();
   // String[] columns={SciHelper.UID,SciHelper.EMAIL,SciHelper.PASSWORD};
    Cursor cursor = db.rawQuery("SELECT _id FROM " + SciHelper.TABLE_NAME + " WHERE email=? AND password=?", new String[]{email, pwd});
    while(cursor.moveToNext())
    {
        int index1=cursor.getColumnIndex(SciHelper.UID);
        int index2=cursor.getColumnIndex(SciHelper.EMAIL);
        int index3=cursor.getColumnIndex(SciHelper.PASSWORD);
        String cid=cursor.getString(index1);
        String mail=cursor.getString(index2);
        String mailpass=cursor.getString(index3);
        buffer.append(cid +" "+mail+" "+mailpass+"\n");
      /*  SharedPreferences sharedPreferences= context.getSharedPreferences("CursorData", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putInt("CursorId", cid);
        editor.commit();*/
    }
   return buffer.toString();
}

code at login class:

public void checkTable(View view) {
    email2 = emaillog.getText().toString();
    pass2 = passlog.getText().toString();
    String data = sciDataBaseAdapter.getData(email2, pass2);
    String[] values=data.split("\\");

    String cid=values(0);
    if (TextUtils.isEmpty(email2)) {
        emaillog.setError("Enter Email Id");
        passlog.setError("Enter Password");
    }

        //   if (email1 != null) {
        Intent intent=new Intent(this,ResultActivity.class);
        startActivity(intent);
        Message.message(this, "Login succesful");
    } else {
        Message.message(this, "Invalid username/ or register");
    }
}

}

Aucun commentaire:

Enregistrer un commentaire