I have 3 activities.
In the first activity, I can edit 4 string type values which are saved in a database.userid,name and phone.
The idea is that a userid can be used multiple times.
So if i give the value userid the string "James" multiple times,in the 2nd Activity i can type in an edit text the string "james" and every value from my database has as userid string "James" will appear in a spinner
public class SecondActivity extends AppCompatActivity {
public DBHelper helper;
public ArrayList<String> theList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
String input =((EditText)findViewById(R.id.editText)).getText().toString();
Spinner spinner = (Spinner) findViewById(R.id.spinner);
helper = new DBHelper(SecondActivity.this);
SQLiteDatabase database = helper.getReadableDatabase();
theList = new ArrayList<>();
Cursor cursor = database.query(DBHelper.TABLE_NAME, new String[]{DBHelper.FIELD_4}, DBHelper.FIELD_1+"=?", new String[]{input}, null, null, null);
if (cursor.moveToFirst())
{
do
{
theList.add(cursor.getString(4));
} while (cursor.moveToNext());
}
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(SecondActivity.this, android.R.layout.simple_spinner_item, theList);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
}
}
That is my code so far and I thought it would work but it doesn't.
NOTE: I can't use raw queries
question from:
https://stackoverflow.com/questions/65602597/edit-text-to-spinner-android-studio 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…