您好我有一个AutoCompleteTextView可以在我的Nexus1上正常工作。在Samsung Apollo i5801上部署代码时,列表无法正确显示。数据在列表中,因为我可以滚动一点(见下面的图片)。
这是我的CursorAdapter
class VenueSuggestionLitsAdpater extends CursorAdapter implements
Filterable {
private HiTechDatabaseAdapter database;
public VenueSuggestionLitsAdpater(Context context, Cursor c) {
super(context, c);
// database = HiTechDatabaseAdapter.getInstance(JobActivity.this);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
int name = cursor.getColumnIndex("name");
int postcode = cursor.getColumnIndex("postcode");
String str = cursor.getString(name) + " - "
+ cursor.getString(postcode);
((TextView) view).setText(str);
}
@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);
int name = cursor.getColumnIndex("name");
int postcode = cursor.getColumnIndex("postcode");
String str = cursor.getString(name) + " - "
+ cursor.getString(postcode);
view.setText(str);
return view;
}
@Override
public CharSequence convertToString(Cursor cursor) {
int columnIndex = cursor.getColumnIndexOrThrow("name");
String name = cursor.getString(columnIndex);
// Log.d("Debug","Convert To String....");
return name;
}
@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (constraint == null) {
Cursor suggestions = HiTechDatabaseAdapter.getInstance(
JobActivity.this).queryVenueName(
HiTechDatabaseAdapter.TABLE_VENUES,
new String[] { "_id", "name", "address", "postcode","venueID" },
"");
return suggestions;
}
Cursor suggestions = HiTechDatabaseAdapter.getInstance(
JobActivity.this).queryVenueName(
HiTechDatabaseAdapter.TABLE_VENUES,
new String[] { "_id", "name", "address", "postcode","venueID" },
constraint.toString());
return suggestions;
}
}
以及如何将我的适配器应用于我的AutoCompleteTextView
VenueSuggestionLitsAdpater suggestionsAdapter = new VenueSuggestionLitsAdpater(
JobActivity.this, suggestions);
venuNameSearch.setAdapter(suggestionsAdapter);
最后我的XML布局
<?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"
android:padding="10px">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/venuetextlabel"
android:text="Venue:"
/>
<AutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/venuesearch"
android:editable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textcampaign"
android:text="Campaign:"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="60px"
android:id="@+id/campaign"
android:drawSelectorOnTop="true"
android:prompt="@string/campaign"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textgender"
android:text="Gender:"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="60px"
android:id="@+id/gender"
android:drawSelectorOnTop="true"
android:prompt="@string/gender"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textreason"
android:text="Reason:"/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="60px"
android:id="@+id/reason"
android:drawSelectorOnTop="true"
android:prompt="@string/reason"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/address_line_1"
android:hint="Address Line 1"
android:editable="false"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/address_postcode"
android:hint="Postcode"
android:editable="false"
/>
<Gallery
android:id="@+id/gallery"
android:layout_marginTop="10px"
android:spacing="10px"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="200px"
android:layout_height="60px"
android:id="@+id/submit"
android:text="Submit"
android:textSize="20sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10px"
/>
</LinearLayout>
非常感谢任何帮助。
干杯