2016-07-11 2 views
-2

Привет, я хочу добавить autocompletetextview в всплывающее окно. Таким образом, когда я набираю название города, оно должно появляться как предложение .. Возможно ли это в PopUpWindow. Пробовал это.Ошибка приложения при добавлении AutoCompleteTextView в PopupWindow?

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 to add window -- token [email protected] is not valid; is your activity running? 
at android.view.ViewRootImpl.setView(ViewRootImpl.java:706) 
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:356) 
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:234) 
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153) 
at android.view.Window$LocalWindowManager.addView(Window.java:559) 
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1013) 
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:922) 
at android.widget.ListPopupWindow.show(ListPopupWindow.java:595) 
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1093) 
at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:956) 
at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:938) 
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4921) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 
at dalvik.system.NativeStart.main(Native Method) 

Вот мой 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 the layout for this fragment 
    Log.d("ClientBookingScreen", "Inside OnCreateView of ClientBookingScreen"); 
    rootView = inflater.inflate(R.layout.bookingrequest, container, false); 
    intialize(rootView); 
    intialSetUp(); 
    loadconfigs(); 
    initializeAddressPopUp(); 
    settingClickListener(); 
    return rootView; 
} 

Методы в 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 to limit his 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 = новый ArrayAdapter (адресpopupView.getContext(), android.R.layout.simple_dropdown_item_1line, CITY); city.setAdapter (адаптер);

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

частная пустота 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 for Spinners 
    dutyType.setOnItemSelectedListener(this); 
    vehicleCategory.setOnItemSelectedListener(this); 
    vehicleType.setOnItemSelectedListener(this); 
} 

Любой suggesstion пожалуйста ...

+0

Показать адрес address.xml. – Drv

+0

вы можете разместить весь фрагмент кода oncreateview, где вы загружаете свой макет? –

+0

что это должно быть ?? Его всплывающее представление, которое я создал? И я отправляю xml-файл –

ответ

0

Пусть вы попробуете это,

Измените onCreateView кодировок, как, как показано ниже.

@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; 
} 

Редакцией:

Скопируйте и вставьте эти строки в oncreateView способом, как это.

@Override общественное мнение onCreateView (LayoutInflater инфлятор, ViewGroup контейнер, Bundle savedInstanceState) {

// Inflate the layout for this 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; 

}

Может быть так, как вы надуть расположение неправильно. Попробуйте приведенный выше код и дайте мне знать.

+0

addressPopUpView - это просто PopUp, и мой rootView - это запрос на бронирование, который я надул. Если я сделаю это, чтобы интуиционировать другой мой основной вид? –

+0

Могу ли я отправить вам этот класс? Если бы ты мог мне помочь. –

+0

@Rahul, так что вы используете пользовательское всплывающее окно для загрузки списка автозаполнения? –

Смежные вопросы