我正在尝试在AlertDialog中添加一个AutoCompleteTextBox,但我不知道如何做到这一点。任何有关相同的帮助将不胜感激。此外,在AutoCompleteTextBox中,我想通过google Places API显示这些地方。我为此实现了google Places API,如果我为此运行网址,则显示结果但是当我在AutoCompleteText框中输入2个或更多字符时,它会显示以下错误:
12-20 15:28:39.020: E/AndroidRuntime(19180): FATAL EXCEPTION: main
12-20 15:28:39.020: E/AndroidRuntime(19180): android.view.InflateException: Binary XML file line #47: Error inflating class fragment
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:371)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.AbsListView.obtainView(AbsListView.java:2340)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1236)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.ListView.measureHeightOfChildren(ListView.java:1250)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1123)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.ListPopupWindow.show(ListPopupWindow.java:532)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1081)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:956)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:938)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.os.Looper.loop(Looper.java:153)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.app.ActivityThread.main(ActivityThread.java:4987)
12-20 15:28:39.020: E/AndroidRuntime(19180): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 15:28:39.020: E/AndroidRuntime(19180): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 15:28:39.020: E/AndroidRuntime(19180): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
12-20 15:28:39.020: E/AndroidRuntime(19180): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
12-20 15:28:39.020: E/AndroidRuntime(19180): at dalvik.system.NativeStart.main(Native Method)
12-20 15:28:39.020: E/AndroidRuntime(19180): Caused by: java.lang.IllegalArgumentException: Binary XML file line #47: Duplicate id 0x7f05000e, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
12-20 15:28:39.020: E/AndroidRuntime(19180): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-20 15:28:39.020: E/AndroidRuntime(19180): ... 22 more
以下是我实现适配器的方式:
AutoCompleteTextView autoCompView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
autoCompView.setAdapter(new PlacesAutoCompleteAdapter(this, R.layout.list_item));
和list_item中的AutoCompleteTextView如下:
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/BookCabtxt"
android:ems="10"
>
</AutoCompleteTextView>
注意:这仅用于试用目的。实际上,我想将此AutoCompleteTextView放在AlertDialog中。所以主要是我有两个疑问:
1>creating an AutoCompleteTextView inside alertDialog
2>Generating results in that AutoCompleteTextView
如果有任何不清楚的地方,请在评论中提出问题,并提前赦免我的英语和无知的开发。
答案 0 :(得分:0)
您需要使用为Dialog创建的视图。你应该有这样的东西。
LayoutInflater factory = LayoutInflater.from(MyActivity.this);
final View textEntryView = factory.inflate(R.layout.my_layout, null);
AutoCompleteTextView textViewCountry = (AutoCompleteTextView)textEntryView.findViewById(com.example.FindItNear.R.id.autocomplete_radius);
以下链接可以为您提供帮助:AutoCompleteTextView implementation on the AlertDialog