I am trying to trap the event OnItemSelected so I can grab the value of the item selected do a db look-up and populate the rest of the fields. I am only getting the first character of the selection.
1) Where is the selected string stored?
2) How do I access the whole string, not just the first character?
3) Is there a better way to implement the listeners? (More flexible)
I have defined my list as:
Using java Syntax Highlighting
- public class SiteListV4 extends Activity
- implements AdapterView.OnItemSelectedListener{
- EditText siteid=null;
- TextView directions=null;
- TextView keysloc=null;
- TextView sitename=null;
- AtomicBoolean isActive=new AtomicBoolean(true);
- SQLiteDatabase sitedb=null;
- Cursor model=null;
- String[] sitelistArray=null;
- AutoCompleteTextView textView = null;
- /** Called when the activity is first created. */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- sitedb=(new SiteListSQLiteHelper(this)).getReadableDatabase();
- model=Site.getAll(sitedb);
- startManagingCursor(model);
- sitelistArray=loadsiteArray(model);
- textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_site);
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.site_list, sitelistArray);
- textView.setAdapter(adapter);
- textView.setOnClickListener(onClick);
- textView.setOnItemSelectedListener(this);
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
I define a listener that is activated on the event:
Using java Syntax Highlighting
- public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
- String s=null;
- EditText et=null;
- android.util.Log.v("ONSELECT", "Item Selected (TRAPPED)");
- et=(EditText)findViewById(R.id.autocomplete_site);
- s=et.getText().toString();
- android.util.Log.v("ONSELECT","Value = " + s);
- android.util.Log.v("ONSELECT","Value = " + position);
- };
- public void onNothingSelected(AdapterView<?> parent) {
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Right now, string s, returns the first character in the field selected. It happens to be the threshold I set in the layout.
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:stretchColumns="1"
- >
- <TableRow>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Site: "
- />
- <AutoCompleteTextView
- android:id="@+id/autocomplete_site"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"
- android:completionThreshold="1"
- />
- </TableRow>
- <TableRow>
- <TextView android:text="Keys loc: " />
- <EditText android:id="@+id/mainkeys" />
- </TableRow>
- </TableLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

