D
D
dnpgk2019-06-12 16:29:26
Java
dnpgk, 2019-06-12 16:29:26

How to form a transition to the next input from the SQL database when performing a certain action?

public class MainActivity extends AppCompatActivity  {

    //Объявим переменные компонентов
    EditText editText;
    TextView text1;

    private DatabaseHelper mDBHelper;
    private SQLiteDatabase mDb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mDBHelper = new DatabaseHelper(this);



    try {
        mDBHelper.updateDataBase();
    } catch (IOException mIOException) {
        throw new Error("UnableToUpdateDatabase");
    }

    try {
        mDb = mDBHelper.getWritableDatabase();
    } catch (SQLException mSQLException) {
        throw mSQLException;
    }

    //Найдем компоненты в XML разметке

    text1 = (TextView) findViewById(R.id.text1);
    editText =  findViewById(R.id.editText);




        String product = "";
        String gono = "";


        final Cursor cursor = mDb.rawQuery("SELECT  * FROM " + "book1" +    " ORDER BY RANDOM() ", null);
        cursor.moveToFirst();
        if ((cursor!=null) && (cursor.getCount() > 0)){
            cursor.moveToFirst();
            product += cursor.getString(1);
            gono += cursor.getString(2);
        }
        cursor.close();

        text1.setText(product);


        final String finalGono = gono;

        editText.setOnKeyListener(new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN &&
                        (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    if (editText.getText().toString().equals(finalGono))

When requesting from the database in TextView (text1) the text of the question, after the answer (in the EditText), whether it is correct or not, display the next random line of the question so that it can also be replaced with the next random line, but only after the answer in the EditText. How to continue for this or transform the code? (product is the question line, gono is the correct answer line).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question