2
我加入觀的ListView在ListActivity頁眉,膨脹具有AutoCompleteTextView並沒有顯示在輸入文本的建議後。雖然它在正常情況下絕對正常,但在添加到ListView標題時無法正常工作。AutoCompleteTextView建議不彈出
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);
}
請讓我知道如果我錯過任何設置?提前致謝。
看起來像它的焦點問題。焦點可能會去listView中的其他組件。 – 2013-03-28 08:15:06