有一个微调器,其中填充了来自设备的联系人。
Cursor contactsCursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME}, ContactsContract.Contacts.HAS_PHONE_NUMBER +" = "+ HAS_PHONE_NUMBER_STATE, null, ContactsContract.Contacts.DISPLAY_NAME +" ASC");
SimpleCursorAdapter sca = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, contactsCursor, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, new int[] {android.R.id.text1});
contactsSpinner.setAdapter(sca);
当我尝试如此设置时
String contactId = getContactSelectedId();
if(null != contactId) {
contactsSpinner.setSelection(Integer.valueOf(contactId));
}
引发异常:
llegalStateException: couldn't move cursor to position x
堆栈跟踪:
07-31 01:07:08.854: E/AndroidRuntime(22745): FATAL EXCEPTION: main
07-31 01:07:08.854: E/AndroidRuntime(22745): java.lang.IllegalStateException: couldn't move cursor to position 1136
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:248)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.widget.Spinner.makeAndAddView(Spinner.java:544)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.widget.Spinner.layout(Spinner.java:495)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.widget.Spinner.onLayout(Spinner.java:459)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.view.View.layout(View.java:14055)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.view.ViewGroup.layout(ViewGroup.java:4604)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
07-31 01:07:08.854: E/AndroidRuntime(22745): at android.view.View.layout(View.java:14055)
我该如何解决这个问题?