AutoCompleteTextView建议没有弹出

时间:2013-03-06 13:32:47

标签: android autocomplete android-listview listactivity

我在ListActivity中将List添加到ListView的Header中,在充气后具有AutoCompleteTextView并且没有显示有关输入文本的建议。虽然它在正常情况下工作得很好,但在添加到ListView的Header时工作不正常。

header_route.xml:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
     <TextView
        android:id="@+id/lblride_From"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/txtFrom"
        android:layout_alignParentTop="true"
        android:text="@string/lblride_Route"
        />

    <AutoCompleteTextView
        android:id="@+id/txtFrom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/lblride_From"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="2dp"
        android:completionThreshold="1"
        android:ems="10"
        android:width="290dp"
        android:imeOptions="actionGo"
        android:popupBackground="@android:color/black" >

        <requestFocus />
    </AutoCompleteTextView>

    <Button
        android:id="@+id/hdbtnOkRoute"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/txtFrom"
        android:layout_below="@+id/txtFrom"
        android:layout_marginTop="2dp"
        android:minHeight="40dp"
        android:text="@string/txtBtnOk"
        android:width="290dp" />

 </RelativeLayout>


public class BusRouteActivity extends ListActivity implements TextWatcher {

    AutoCompleteTextView actvFrom;
    Button buttonOK;
    TextView txtViewRouteItem;
    ListView lstViewRoute;
    ArrayAdapter<String> listAdapter;
    DataBaseHelper databaseHelper;
    TextView tvFooter;
    Context appContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.nameBusRouteActivity);
        appContext = getApplicationContext();
        lstViewRoute = getListView();
        LayoutInflater inflater = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        View view = inflater.inflate(R.layout.header_route, null);

        DataBaseHelper dbh = new DataBaseHelper(getApplicationContext());

        try {
            dbh.createDataBase();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();            
        }

        dbh.openDataBase();
        databaseHelper = dbh;

    actvFrom = (AutoCompleteTextView) view.findViewById(R.id.txtFrom);
        actvFrom.addTextChangedListener(this);
        actvFrom.setOnEditorActionListener(actionListener);
        ArrayAdapter<String> aroutes = new ArrayAdapter<String>(appContext, R.layout.routeitem, dbh.GetRoutes());
        actvFrom.setAdapter(aroutes);

        buttonOK = (Button)view.findViewById(R.id.hdbtnOkRoute);
        buttonOK.setOnClickListener(OkOnClickListener);

        tvFooter = new TextView(this);
        tvFooter.setTextAppearance(getApplicationContext(), R.style.footerStyle);
        String text = getResources().getString(R.string.footer);
        tvFooter.setText(Html.fromHtml(text));

        listAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.routeitem);
        lstViewRoute.addHeaderView(view, null, false);
        lstViewRoute.addFooterView(tvFooter, null, true);
        lstViewRoute.setClickable(true);
        lstViewRoute.setSelected(true);
        lstViewRoute.setAdapter(listAdapter);
    }

如果我错过任何设置,请告诉我?提前致谢。

1 个答案:

答案 0 :(得分:0)