I have successfully implemented my AutoCompleteTextView which is based off an SQLite query and is placed in an array adapter. That's all working beautifully, however I can't get my onclickevent working.
I just want to create an intent to pass the selected value to a new activity. I know how to create an onclicklistener. I am just unsure about how to apply it to the dropdown box of the AutoCompleteTextView.
Nevermind. I've solved it. I was just executing poorly. The code below autocompletes my textview based off a simple SELECT SQLite statement and executes when the user selects the university from the dropdown list.
The onclick event creates a new intent and starts a new activity passing the selection to this activity within the intent.
final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.ac_university);
String[] universities = myDbHelper.getAllUnis(db);
// Print out the values to the log
for(int i = 0; i < universities.length; i++)
{
Log.i(this.toString(), universities[i]);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, universities);
textView.setAdapter(adapter);
//textView.setOnItemSelectedListener(this);
textView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intent = new Intent(Main.this, Campus.class);
Bundle bundle = new Bundle();
bundle.putString("university_name", arg0.getItemAtPosition(arg2).toString());
bundle.putLong("_id", arg3);
intent.putExtras(bundle);
startActivity(intent);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With