bump
for information, here is the adapter i use for the
AutocompleteTextView :
import java.io.InputStream;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
public class ContactListAdapter extends CursorAdapter implements
Filterable {
public static final String[] PEOPLE_PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
private ContentResolver mContent;
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
mContent = context.getContentResolver();
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup
parent) {
View v =
LayoutInflater.from(context).inflate(R.layout.player_item_autocomplete,
null);
TextView name = (TextView) v.findViewById(R.id.playerName);
name.setText(cursor.getString(1));
Uri contactPhotoUri =
ContentUris.withAppendedId(Contacts.CONTENT_URI, cursor.getLong(0));
InputStream image_stream =
Contacts.openContactPhotoInputStream(mContent, contactPhotoUri);
if (image_stream != null) {
ImageView badge = (ImageView) v.findViewById(R.id.playerPhoto);
badge.setImageBitmap(BitmapFactory.decodeStream(image_stream));
}
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView name = (TextView) view.findViewById(R.id.playerName);
name.setText(cursor.getString(1));
Uri contactPhotoUri =
ContentUris.withAppendedId(Contacts.CONTENT_URI, cursor.getLong(0));
InputStream image_stream =
Contacts.openContactPhotoInputStream(mContent, contactPhotoUri);
if (image_stream != null) {
ImageView badge = (ImageView)
view.findViewById(R.id.playerPhoto);
badge.setImageBitmap(BitmapFactory.decodeStream(image_stream));
}
}
@Override
public String convertToString(Cursor cursor) {
return cursor.getString(1);
}
@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(ContactsContract.Contacts.DISPLAY_NAME);
buffer.append(") GLOB ?");
args = new String[] { constraint.toString().toUpperCase()
+ "*" };
}
return mContent.query(ContactsContract.Contacts.CONTENT_URI,
ContactListAdapter.PEOPLE_PROJECTION, buffer == null ? null :
buffer.toString(), args, ContactsContract.Contacts.DISPLAY_NAME + "
COLLATE LOCALIZED ASC");
}
}
On Nov 17, 5:36 pm, Christophe <[email protected]>
wrote:
> Hello,
>
> I have an AutoCompleteTextView with suggest the name of the people in
> the contact list. I display a custom view with the photo and the name
> of the contact in the suggestion. It works perfectly, except nothing
> happen when I click on one of the suggested item ...
>
> The view that I use :
>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:layout_height="wrap_content"
> android:minHeight="58dip"
> android:layout_width="fill_parent"
> android:orientation="horizontal"
> android:gravity="center_vertical"
> android:focusable="true"
>
> android:background="@android:drawable/list_selector_background"
> android:clickable="true">
>
> <ImageView android:layout_height="54dip"
> android:layout_marginLeft="2dip"
> android:layout_marginRight="14dip"
> android:layout_width="54dip"
> android:id="@+id/playerPhoto"
> android:src="@drawable/contact_picture"></ImageView>
>
> <TextView android:layout_width="fill_parent"
>
> android:textAppearance="?android:attr/textAppearanceMedium"
> android:maxLines="1"
> android:ellipsize="end"
> android:layout_weight="1"
> android:layout_height="fill_parent"
> android:id="@+id/playerName"
> android:text="name"
> android:layout_gravity="center_vertical"
> android:gravity="center_vertical"
> android:textColor="#000000"
> android:clickable="true"/>
>
> </LinearLayout>
>
> ideas ?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en