Android AutoCompleteTextView 无法正确渲染?
您好,我有一个 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>
任何帮助将不胜感激。
干杯
Hi I have a AutoCompleteTextView which works fine on my Nexus1. When deploying the code on a Samsung Apollo i5801 the list doesn't display correctly. The data is in the list as I can scroll a little (see pics below).
Here is my 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;
}
}
And how I apply my adapter to my AutoCompleteTextView
VenueSuggestionLitsAdpater suggestionsAdapter = new VenueSuggestionLitsAdpater(
JobActivity.this, suggestions);
venuNameSearch.setAdapter(suggestionsAdapter);
Finally my XML layout
<?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>
Any help would be much appreciated.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论