android - App crashes when adding AutoCompleteTextView in PopupWindow? -
hello want add autocompletetextview in popup. such when type city name should come suggestion.. possible in popupwindow. trying this.
view addresspopupview =addresslayoutinflater.inflate(r.layout.addressinput, null); autocompletetextview city = (autocompletetextview) addresspopupview.findviewbyid(r.id.city); string[] city ={"mumbai", "ahemadabad", "kolkata", "chennai", "thane"}; arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_dropdown_item_1line, city); city.setadapter(adapter); popupwindow addresspopupwindow = new popupwindow(addresspopupview, viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content, true); addresspopupwindow.showatlocation(addresspopupview, gravity.center, 0, 0);
logcat
fatal exception: main android.view.windowmanager$badtokenexception: unable add window -- token android.view.viewrootimpl$w@424c2b38 not valid; activity running? @ android.view.viewrootimpl.setview(viewrootimpl.java:706) @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:356) @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:234) @ android.view.windowmanagerimpl$compatmodewrapper.addview(windowmanagerimpl.java:153) @ android.view.window$localwindowmanager.addview(window.java:559) @ android.widget.popupwindow.invokepopup(popupwindow.java:1013) @ android.widget.popupwindow.showasdropdown(popupwindow.java:922) @ android.widget.listpopupwindow.show(listpopupwindow.java:595) @ android.widget.autocompletetextview.showdropdown(autocompletetextview.java:1093) @ android.widget.autocompletetextview.updatedropdownforfilter(autocompletetextview.java:956) @ android.widget.autocompletetextview.onfiltercomplete(autocompletetextview.java:938) @ android.widget.filter$resultshandler.handlemessage(filter.java:285) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4921) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) @ dalvik.system.nativestart.main(native method)
here addressinput.xml
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:elevation="@dimen/dimen_4dp" android:orientation="vertical" android:padding="@dimen/dimen_4dp"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/addresspopuptitle" android:textappearance="?android:attr/textappearancelarge" android:gravity="center_horizontal"/> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <edittext android:id="@+id/addressline1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginright="2dp" android:layout_weight="1" android:hint="address line 1" /> <edittext android:id="@+id/addressline2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="address line 2" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <edittext android:id="@+id/landmark" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginright="2dp" android:layout_weight="1" android:hint="landmark" /> <edittext android:id="@+id/locality" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="locality" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <!--<edittext--> <!--android:id="@+id/city"--> <!--android:layout_width="0dp"--> <!--android:layout_height="wrap_content"--> <!--android:layout_marginright="2dp"--> <!--android:layout_weight="1"--> <!--android:hint="city" />--> <autocompletetextview android:id="@+id/city" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginright="2dp" android:layout_weight="1" android:hint="city" /> <edittext android:id="@+id/pin" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="pin" /> </linearlayout> <edittext android:id="@+id/state" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="state" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <button android:id="@+id/summitaddrpopup" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="summit" android:textcolor="@color/green" /> <button android:id="@+id/canceladdrpopup" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="cancel" android:textcolor="@color/red" /> </linearlayout>
oncreateview:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment log.d("clientbookingscreen", "inside oncreateview of clientbookingscreen"); rootview = inflater.inflate(r.layout.bookingrequest, container, false); intialize(rootview); intialsetup(); loadconfigs(); initializeaddresspopup(); settingclicklistener(); return rootview; }
the methods in oncreateview() :
private void intialize(view rootview) { //setting toolbar mycalendar = calendar.getinstance(timezone.gettimezone("asia/calcutta")); pickupdate = (textview) rootview.findviewbyid(r.id.pickupdateinput); pickuptime = (textview) rootview.findviewbyid(r.id.pickuptimeinput); returndate = (textview) rootview.findviewbyid(r.id.returndateinput); returntime = (textview) rootview.findviewbyid(r.id.returntimeinput); pickupaddress = (textview) rootview.findviewbyid(r.id.pickupaddressinput); pickupaddress.setmovementmethod(new scrollingmovementmethod()); returnaddress = (textview) rootview.findviewbyid(r.id.returnaddressinput); returnaddress.setmovementmethod(new scrollingmovementmethod()); description = (edittext) rootview.findviewbyid(r.id.descriptioninput); description.setmovementmethod(new scrollingmovementmethod()); book = (button) rootview.findviewbyid(r.id.bookbutton); //spinners dutytype = (spinner) rootview.findviewbyid(r.id.dutytypeinput); vehiclecategory = (spinner) rootview.findviewbyid(r.id.vehiclecategoryinput); vehicletype = (spinner) rootview.findviewbyid(r.id.vehicletypeinput); //creating reflection of spinner limit height createreflectionofspinner(dutytype); createreflectionofspinner(vehiclecategory); createreflectionofspinner(vehicletype); isdraweropened = false; //checkbox btccheckbox = (checkbox) rootview.findviewbyid(r.id.btccheckbox); } private void loadconfigs() { categorymap = new hashmap<string, arraylist<string>>(); guestaddressmap = new hashmap<string, string>(); guestaddresslabel = new arraylist<string>(); categoryname = new arraylist<string>(); dutytypename = new arraylist<string>(); new loadconfigs().execute(); } private void initializeaddresspopup() { //address input popup addresslayoutinflater = (layoutinflater) getactivity().getbasecontext().getsystemservice(context.layout_inflater_service); addresspopupview = addresslayoutinflater.inflate(r.layout.addressinput, null); addressline1 = (edittext) addresspopupview.findviewbyid(r.id.addressline1); addressline2 = (edittext) addresspopupview.findviewbyid(r.id.addressline2); landmark = (edittext) addresspopupview.findviewbyid(r.id.landmark); locality = (edittext) addresspopupview.findviewbyid(r.id.locality); city = (autocompletetextview) addresspopupview.findviewbyid(r.id.city); string[] city ={"mumbai", "ahemadabad", "kolkata", "chennai", "thane"};
// autocompletetextview textview = (autocompletetextview) findviewbyid(r.id.actv_country); arrayadapter adapter = new arrayadapter(addresspopupview.getcontext(), android.r.layout.simple_dropdown_item_1line, city); city.setadapter(adapter);
pin = (edittext) addresspopupview.findviewbyid(r.id.pin); state = (edittext) addresspopupview.findviewbyid(r.id.state); title = (textview) addresspopupview.findviewbyid(r.id.addresspopuptitle); addresssummit = (button) addresspopupview.findviewbyid(r.id.summitaddrpopup); addresscancel = (button) addresspopupview.findviewbyid(r.id.canceladdrpopup); //addresslabellist popoup addresslabelinflater = (layoutinflater) getactivity().getbasecontext().getsystemservice(context.layout_inflater_service); listofaddresstitle = addresslabelinflater.inflate(r.layout.addresslabellist, null); addresslabellistview = (listview) listofaddresstitle.findviewbyid(r.id.addresslabellistview); selectedlistok = (button) listofaddresstitle.findviewbyid(r.id.addresslabellistbutton); }
private void settingclicklistener() {
pickupdate.setonclicklistener(this); pickuptime.setonclicklistener(this); returndate.setonclicklistener(this); returntime.setonclicklistener(this); pickupaddress.setonclicklistener(this); returnaddress.setonclicklistener(this); addresssummit.setonclicklistener(this); addresscancel.setonclicklistener(this); book.setonclicklistener(this); btccheckbox.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (((checkbox) v).ischecked()) { toast.maketext(getactivity(), "checked", toast.length_long).show(); isbtc = true; } else { toast.maketext(getactivity(), "unchecked", toast.length_long).show(); isbtc = false; } } }); //on item listener spinners dutytype.setonitemselectedlistener(this); vehiclecategory.setonitemselectedlistener(this); vehicletype.setonitemselectedlistener(this); }
any suggesstion please...
let try this,
change oncreateview codings below.
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view addresspopupview =inflater.inflate(r.layout.addressinput, container, false); autocompletetextview city = (autocompletetextview) addresspopupview.findviewbyid(r.id.city); string[] city ={"mumbai", "ahemadabad", "kolkata", "chennai", "thane"}; arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_dropdown_item_1line, city); city.setadapter(adapter); popupwindow addresspopupwindow = new popupwindow(addresspopupview, viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content, true); addresspopupwindow.showatlocation(addresspopupview, gravity.center, 0, 0); return addresspopupview; }
edited :
copy paste these lines in oncreateview method this.
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {
// inflate layout fragment log.d("clientbookingscreen", "inside oncreateview of clientbookingscreen"); rootview = inflater.inflate(r.layout.bookingrequest, container, false); autocompletetextview city = (autocompletetextview) rootview.findviewbyid(r.id.city); string[] city ={"mumbai", "ahemadabad", "kolkata", "chennai", "thane"}; arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_dropdown_item_1line, city); city.setadapter(adapter); intialize(rootview); intialsetup(); loadconfigs(); initializeaddresspopup(); settingclicklistener(); return rootview;
}
may way inflate layout wrong. try above code , let me know.
Comments
Post a Comment