Здравствуйте. В приложении есть activity, в котором задается вопрос и выбирается один ответ, путем нажатия на кнопку.
package com.example.eugene.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener {
Button green;
Button red;
Button blue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
green = findViewById(R.id.green);
red = findViewById(R.id.red);
blue = findViewById(R.id.blue);
green.setOnClickListener(this);
red.setOnClickListener(this);
blue.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.green:
Intent intent = new Intent(this, one.class);
startActivity(intent);
break;
case R.id.red:
Intent intent1 = new Intent(this, two.class);
startActivity(intent1);
break;
case R.id.blue:
Intent intent2 = new Intent(this, three.class);
startActivity(intent2);
break;
default:
break;
}
}
}
При нажатию на кнопку, нас перекидывает на новый Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.eugene.myapplication.MainActivity">
<TextView
android:id="@+id/Head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Выберите цвет!">
</TextView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:text="Зеленый">
</Button>
<Button
android:id="@+id/red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:text="Красный">
</Button>
<Button
android:id="@+id/blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:text="Синий">
</Button>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Есть база данных с набором определенных значений:

Зеленый цвет = 1. Красный = 2. Синий = 3.
Базу добавил в папку assets в директории приложения.

Собственно вопрос. Подскажите как организовать взаимодействия моего activity с БД, чтобы при нажатии допустим кнопки "зеленый", мне фильтровало БД и выдавало только строки с этим параметром. А если в последствии будет второе activity, но уже с другим вопросом, как связать два этих поиска чтобы уже по результату сортировки по двум activity, выдавала мне оставшиеся в процессе отсеивания результаты. Спасибо