1

I am trying to add an AutoCompleteTextBox inside an AlertDialog but I have no Idea how to do that. Any help regarding the same would be appreciated. Also In that AutoCompleteTextBox , I want to display the places through google Places API. I have implemented the google Places API for that and it shows the result if I run the url for that but when I enter 2 or more character in the AutoCompleteText Box it shows the following Error:

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

Below is how I implemented the adapter:

AutoCompleteTextView autoCompView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
autoCompView.setAdapter(new PlacesAutoCompleteAdapter(this, R.layout.list_item));

and the AutoCompleteTextView in list_item is as follows:

<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>

Note: This is just for trial purpose. In actual , I want to put this AutoCompleteTextView inside an AlertDialog. So Mainly I have 2 Doubts:

1>creating an AutoCompleteTextView inside alertDialog
2>Generating results in that AutoCompleteTextView

If there is anything that is not clear please ask in the comments.thanks in advance and pardon my english and ignorance in andoid development as well.

Puneetr90
  • 199
  • 1
  • 6
  • 18

1 Answers1

0

You need to use the view you created for the Dialog. You should have something that looks like this.

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);

Here is a link which may help you: AutoCompleteTextView implementation on the AlertDialog

Community
  • 1
  • 1