自定义联系人光标适配器中未获取电话号码
|
我正在尝试实现一个自定义光标适配器以显示联系人姓名和电话号码。但是我只收到姓名和电话号码为null的消息。请帮我弄清楚为什么我将电话号码作为null的原因。
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:orientation=\"vertical\"
android:layout_width=\"fill_parent\"
android:layout_height=\"fill_parent\"
>
<AutoCompleteTextView android:id=\"@+id/autotextContacts\"
android:completionThreshold=\"1\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"/>
<TextView
android:id=\"@+id/namelabel\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:textSize=\"20sp\"
/>
<TextView
android:id=\"@+id/numberlabel\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:textSize=\"10sp\"
android:layout_below = \"@id/namelabel\"
/>
private AutoCompleteTextView destination;
private ContentResolver mContentResolver;
private static final String[] PEOPLE_PROJECTION = new String[] {
People._ID,
People.NAME,
People.NUMBER
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_view);
mContentResolver = getContentResolver();
Cursor cursor = managedQuery(
People.CONTENT_URI, PEOPLE_PROJECTION, null,
null, null);
if(cursor == null ){
Log.i(getClass().getSimpleName(),\"cursor null\");
}
CallListAdapter adapter = new CallListAdapter(this, cursor);
destination = (AutoCompleteTextView) findViewById(R.id.autotextContacts);
destination.setAdapter(adapter);
}
public static class CallListAdapter extends CursorAdapter implements
Filterable {
Context context;
private ContentResolver mContent;
public CallListAdapter(Context context, Cursor c) {
super(context, c, true);
mContent = context.getContentResolver();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = (View) inflater.inflate(R.layout.contacts_view, parent, false);
TextView tx = (TextView) view.findViewById(R.id.namelabel);
tx.setText(cursor.getString(cursor.getColumnIndex(People.NAME)));
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tx = (TextView) view.findViewById(R.id.rishi_label);
tx.setText(cursor.getString(cursor.getColumnIndex(People.NAME)));
Log.i(\"LOG\",\"Contact NAME\" + cursor.getString(cursor.getColumnIndex(People.NAME)));
int numbercolumn = cursor.getColumnIndex(People.NUMBER);
String number;
number = cursor.getString(numbercolumn);
Log.i(\"LOG\", \"Contact NUMBER\" + number);
}
@Override
public String convertToString(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(People.NAME));
}
@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(\"UPPER(\");
buffer.append(Contacts.People.NAME);
buffer.append(\") GLOB ?\");
args = new String[] { constraint.toString().toUpperCase() + \"*\" };
}
return mContent.query(Contacts.People.CONTENT_URI,
PEOPLE_PROJECTION, buffer == null ? null : buffer
.toString(), args,
null);
}
}
谢谢
没有找到相关结果
已邀请:
2 个回复
勘掸府迫路
磋判粗惊