Hello, I am trying create listview as under for dropdown for
autocompletetextview. but I am getting classcast view for that. Anyone
can tell me why is it? What could be possible solution??
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 LayoutInflater inflater = LayoutInflater.from(context);
/*final TextView view = (TextView) inflater.inflate(
android.R.layout.simple_dropdown_item_1line, parent,
false);
view.setText(cursor.getString(5));*/
final ListView view = (ListView)inflater.inflate
(R.layout.auto_view, parent,false);
final TextView autoContact = (TextView)view.findViewById
(R.id.AutoContact);
final TextView autoName = (TextView)view.findViewById
(R.id.AutoName);
autoName.setText(cursor.getString(5));
autoContact.setText(cursor.getString(3));
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
//((TextView) view).setText(cursor.getString(5));
String from[] = {cursor.getString(3),cursor.getString(5)};
int to[] = {R.id.AutoContact,R.id.AutoName};
ListAdapter listAdapter = new SimpleCursorAdapter
(context,R.layout.auto_view,cursor,from,to);
((ListView)view).setAdapter(listAdapter);
}
XML file:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:padding="3dp" xmlns:android="http://schemas.android.com/apk/
res/android">
<TextView android:id="@+id/AutoName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
<TextView android:id="@+id/AutoContact"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
Thanks!!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---