mercredi 27 avril 2016

How to compare data which is entered by user in EditText and retrieve result data in the EditText from sqlite database in android studio 2.0

              //I am learning android. I am trying to create an application that takes data from user in EditText. Compare that data into SQLite database and return data in another EditText.
        After running my code application is closing i.e.Force Close. i.e. Unfortunately your application is closed.
                    Please help me to compare and retrieve data from sqlite database and display it in EditText.    

    My Code is:
DatabaseHelper Class:
     public Cursor getData() {
            SQLiteDatabase db = this.getWritableDatabase();
            String english = et1.getText().toString();

//Query to check data in database Cursor cursor = db.rawQuery("select MSICTm_AutoTarget_Word from" + TABLE_NAME + "where MDICTm_Source_Word="+english, null); et2.setText(""); if (cursor!=null) { cursor.moveToFirst(); do { String MSICTm_AutoTarget_Word = cursor.getString(cursor.getColumnIndex("MSICTm_AutoTarget_Word")); et2.append("MSICTm_AutoTarget_Word"+cursor.getString(2)+cursor); } while (cursor.moveToNext()); } return cursor; }

Main Activity Class:

 public void viewData() {
        b1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Cursor cursor = mydb.getData();
                if (cursor != null) {
                    if (cursor.moveToFirst()) {
                        do {
                            String MSICTm_AutoTarget_Word = cursor.getString(cursor.getColumnIndex("MSICTm_AutoTarget_Word"));
                            et2.append("MSICTm_AutoTarget_Word" + MSICTm_AutoTarget_Word + cursor);
                        }
                        while (cursor.moveToNext());
                    }
                }
            }
 });
    }

Aucun commentaire:

Enregistrer un commentaire