我使用autoCompleteTextView加载联系人。没有错误,也没有崩溃。但是autocompleteTextview似乎没有出现任何东西。我会发布我的代码和logcat。
代码: - 包com.droidnova.android.samples;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.provider.Contacts.People;
import android.provider.SyncStateContract.Constants;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.CursorAdapter;
import android.widget.Filterable;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AutoComplete extends Activity {
private static TextView mName;
private static TextView mNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.button);
ContentResolver content = getContentResolver();
Cursor cursor = content.query(People.CONTENT_URI,
PEOPLE_PROJECTION, People.NAME+"IS NOT NULL AND" +
People.NUMBER_KEY+"IS NOT NULL",null,People.DEFAULT_SORT_ORDER);
ContactListAdapter adapter = new ContactListAdapter(this, cursor);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.AutoCompleteTextView01);
textView.setAdapter(adapter);
textView.setHint("type name");
}
// XXX compiler bug in javac 1.5.0_07-164, we need to implement Filterable
// to make compilation work
public static class ContactListAdapter extends CursorAdapter implements Filterable {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
mContent = context.getContentResolver();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LinearLayout ret = new LinearLayout(context);
final LayoutInflater inflater = LayoutInflater.from(context);
mName = (TextView) inflater.inflate(
android.R.layout.simple_dropdown_item_1line, parent, false);
mNumber=(TextView) inflater.inflate(
android.R.layout.simple_dropdown_item_1line, parent, false);
int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
int numberIdx = cursor.getColumnIndex(People.NUMBER);
String name = cursor.getString(nameIdx);
String number = cursor.getString(numberIdx);
mName.setText(name);
mNumber.setText(number);
return ret;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
int numberIdx = cursor.getColumnIndex(People.NUMBER);
String name = cursor.getString(nameIdx);
String number = cursor.getString(numberIdx);
((TextView) ((LinearLayout) view).getChildAt(0)).setText(name);
LinearLayout horizontal = (LinearLayout) ((LinearLayout) view).getChildAt(1);
((TextView) horizontal.getChildAt(0)).setText(number);
}
@Override
public String convertToString(Cursor cursor) {
int numCol = cursor.getColumnIndexOrThrow(People.NUMBER);
String number = cursor.getString(numCol);
return number;
}
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); }
StringBuilder buffer = null;
String[] args = null;
if (constraint != null) {
buffer = new StringBuilder();
buffer.append(People.NAME + " IS NOT NULL AND " + People.NUMBER_KEY + " IS NOT NULL AND ");
buffer.append("UPPER(");
buffer.append(People.NAME);
buffer.append(") GLOB ?");
args = new String[] { constraint.toString().toUpperCase() + "*" };
}
return mContent.query(People.CONTENT_URI,PEOPLE_PROJECTION, buffer == null ? null : buffer
.toString(), args, People.DEFAULT_SORT_ORDER);
}
private ContentResolver mContent;
}
private static final String[] PEOPLE_PROJECTION = new String[] {
People.NAME,
People._ID,
People.NUMBER,
};
}
这是我的logcat:
12-14 07:26:46.711: INFO/ActivityManager(59): Start proc com.droidnova.android.samples for activity com.droidnova.android.samples/.SelectContact: pid=250 uid=10025 gids={1015}
12-14 07:26:46.721: ERROR/AndroidRuntime(244): ERROR: thread attach failed
12-14 07:26:46.761: DEBUG/dalvikvm(244): LinearAlloc 0x0 used 639500 of 5242880 (12%)
12-14 07:26:46.941: DEBUG/ddm-heap(250): Got feature list request
12-14 07:26:47.091: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x49e2e8:0x49e464] in 1288362 ns
12-14 07:26:47.111: WARN/ActivityThread(250): Application com.droidnova.android.samples is waiting for the debugger on port 8100...
12-14 07:26:47.141: INFO/System.out(250): Sending WAIT chunk
12-14 07:26:47.151: INFO/dalvikvm(250): Debugger is active
12-14 07:26:47.211: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x4a2798:0x4a28a4] in 571302 ns
12-14 07:26:47.351: INFO/System.out(250): Debugger has connected
12-14 07:26:47.361: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.561: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.761: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:47.781: INFO/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x393188:0x393244] in 604406 ns
12-14 07:26:47.801: INFO/ARMAssembler(59): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x393dd0:0x393f98] in 666356 ns
12-14 07:26:47.961: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.161: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.371: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.571: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.782: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:48.981: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.181: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.391: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.593: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.791: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:49.996: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.201: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.401: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.601: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:50.801: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.012: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.216: INFO/System.out(250): waiting for debugger to settle...
12-14 07:26:51.421: INFO/System.out(250): debugger has settled (1459)
12-14 07:26:51.971: WARN/Resources(250): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f060000}
12-14 07:26:52.931: INFO/ActivityManager(59): Displayed activity com.droidnova.android.samples/.SelectContact: 6292 ms (total 6292 ms)
12-14 07:26:58.051: DEBUG/ViewFlipper(99): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
12-14 07:26:58.051: DEBUG/ViewFlipper(99): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false
12-14 07:26:58.611: DEBUG/dalvikvm(105): GC freed 2632 objects / 154776 bytes in 515ms
12-14 07:27:02.341: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:02.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:02.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:06.391: DEBUG/dalvikvm(170): GC freed 726 objects / 53656 bytes in 106ms
12-14 07:27:26.941: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:26.951: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:26.951: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:30.351: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:30.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:30.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:33.401: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:33.401: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:33.401: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:37.211: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:37.211: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:37.211: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:38.371: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:38.371: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:38.381: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:39.351: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:39.351: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:39.351: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:39.931: ERROR/MediaPlayerService(30): error: -2
12-14 07:27:39.931: ERROR/MediaPlayer(59): Unable to to create media player
12-14 07:27:39.941: WARN/AudioService(59): MediaPlayer IOException: java.io.IOException: setDataSource failed.: status=0x80000000
12-14 07:27:49.261: DEBUG/AndroidRuntime(267): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-14 07:27:49.271: DEBUG/AndroidRuntime(267): CheckJNI is ON
12-14 07:27:49.491: DEBUG/AndroidRuntime(267): --- registering native functions ---
12-14 07:27:49.891: DEBUG/ddm-heap(267): Got feature list request
12-14 07:27:50.431: DEBUG/AndroidRuntime(267): Shutting down VM
12-14 07:27:50.431: DEBUG/dalvikvm(267): DestroyJavaVM waiting for non-daemon threads to exit
12-14 07:27:50.431: DEBUG/dalvikvm(267): DestroyJavaVM shutting VM down
12-14 07:27:50.441: DEBUG/dalvikvm(267): HeapWorker thread shutting down
12-14 07:27:50.441: DEBUG/dalvikvm(267): HeapWorker thread has shut down
12-14 07:27:50.451: ERROR/AndroidRuntime(267): ERROR: thread attach failed
12-14 07:27:50.451: DEBUG/jdwp(267): JDWP shutting down net...
12-14 07:27:50.451: INFO/dalvikvm(267): Debugger has detached; object registry had 1 entries
12-14 07:27:50.471: DEBUG/dalvikvm(267): VM cleaning up
12-14 07:27:50.491: DEBUG/dalvikvm(267): LinearAlloc 0x0 used 629532 of 5242880 (12%)
12-14 07:27:50.981: DEBUG/AndroidRuntime(275): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
12-14 07:27:50.981: DEBUG/AndroidRuntime(275): CheckJNI is ON
12-14 07:27:51.251: DEBUG/AndroidRuntime(275): --- registering native functions ---
12-14 07:27:51.641: DEBUG/ddm-heap(275): Got feature list request
12-14 07:27:52.222: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.droidnova.android.samples/.SelectContact }
12-14 07:27:52.242: DEBUG/AndroidRuntime(275): Shutting down VM
12-14 07:27:52.252: DEBUG/dalvikvm(275): DestroyJavaVM waiting for non-daemon threads to exit
12-14 07:27:52.252: DEBUG/dalvikvm(275): DestroyJavaVM shutting VM down
12-14 07:27:52.252: DEBUG/dalvikvm(275): HeapWorker thread shutting down
12-14 07:27:52.262: DEBUG/dalvikvm(275): HeapWorker thread has shut down
12-14 07:27:52.262: ERROR/AndroidRuntime(275): ERROR: thread attach failed
12-14 07:27:52.272: DEBUG/jdwp(275): JDWP shutting down net...
12-14 07:27:52.272: INFO/dalvikvm(275): Debugger has detached; object registry had 1 entries
12-14 07:27:52.292: DEBUG/dalvikvm(275): VM cleaning up
12-14 07:27:52.331: DEBUG/dalvikvm(275): LinearAlloc 0x0 used 639500 of 5242880 (12%)