Note that there are some explanatory texts on larger screens.

plurals
  1. POCursor returning empty with OnItemClickListener for AutoComplete
    text
    copied!<p>I am using the built in AutoCompleteTextView and I build it's drop down list with this code:</p> <pre><code>autoComp = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); Uri filterUri; if (filterText == null) {filterUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;}else{filterUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, Uri.encode(filterText + "%"));} String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}; Cursor people = getContentResolver().query(filterUri, projection, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); startManagingCursor(people); sca = new SimpleCursorAdapter(this, R.layout.autotextitem, people, new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER}, new int[] {R.id.textView1, R.id.textView2}); autoComp.setAdapter(sca); autoComp.setThreshold(0); </code></pre> <p>When the user selects an item from the dropdown I receive a Cursor out of bounds exception. "CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0"</p> <p>Here is my code declaring the OnClickEvent inside the onCreate method for my activity:</p> <pre><code> autoComp.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; listView, View view, int position, long id) { // Get the cursor, positioned to the corresponding row in the // result set Cursor cursor = (Cursor) sca.getItem(position); // Get the state's capital from this row in the database. String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); // Update the parent class's TextView TextView textViewTo = (TextView) findViewById(R.id.textViewNames); textViewTo.setText((CharSequence) cursor); } }); </code></pre> <p>What could be causing the cursor to be empty?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload