Answer the question
In order to leave comments, you need to log in
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))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question