Android AutoCompleteTextView 无法正确渲染?

发布于 2024-11-06 02:08:36 字数 5556 浏览 0 评论 0原文

您好,我有一个 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).

enter image description hereenter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文