How to show a spinner or autocomplete textview on a popup window? In my application i need to show a popup window which contains spinner or a custom dropdown list. If it is not possible over a popup window, what is the alternative solution?
Asked
Active
Viewed 2,991 times
3 Answers
2
if you want to show spinner on popup the u have to set the android:spinnerMode="dialog" for the spinner.. and yes you have to make a custum layout for the popup and inflate it.
here is my code :
LayoutInflater layoutInflater = (LayoutInflater)IOStatusActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE)
final View popupView = layoutInflater.inflate(R.layout.popupai, null);
final PopupWindow popupWindowDi = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
final TextView txtReadVal = (TextView)popupView.findViewById(R.id.lblPopUpAiReadFrmPLC);
final EditText txtExpVal = (EditText)popupView.findViewById(R.id.txtPopUpAiExpVal);
Button btnDismiss = (Button)popupView.findViewById(R.id.btnPopUpAiCancle);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
popupWindowDi.dismiss();
}});`
you can add ur spinner as i added the button and edit text. hope it help.
grv_9098
- 465
- 5
- 16
-
here is the example code for inflating your popup layout: LayoutInflater layoutInflater = (LayoutInflater)IOStatusActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE); final View popupView = layoutInflater.inflate(R.layout.popupai, null); final PopupWindow popupWindowDi = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); – grv_9098 Jul 17 '12 at 09:42
-
here popupai is the layout of popup that you can create on xml. IOStatusActivity is the name of activity in wich you want to show the popup. – grv_9098 Jul 17 '12 at 09:44
-
thanks for your answer, the spinner works fine with android:spinnerMode="dialog"on a popup window. how can i show a autocomplete textview? – Raneez Ahmed Jul 17 '12 at 09:51
-
because i customize autocomplete textview to create a dropdown list. – Raneez Ahmed Jul 17 '12 at 09:52
-
what is stopping you u do add autocomplete textview ?? do you get any error ?? – grv_9098 Jul 17 '12 at 10:10
-
add autocomplete textview in xml do same as done in the code with normal textview. – grv_9098 Jul 17 '12 at 10:21
-
autocomplete textview uses popup window to show its dropdown list, and its not possible to show a popup over another popup. – Raneez Ahmed Jul 17 '12 at 10:38
-
yes its true.. because the activity is in pause and not actully running. better to avoid the autocomplete textview and try to search a way around. – grv_9098 Jul 17 '12 at 10:51
-
1one more thing if you use textview in popup set: android:inputType="textNoSuggestions" other wise ur activity ma crash. personal experience. – grv_9098 Jul 17 '12 at 10:52
-
the above example(by Ram kiran) is of AlertDialog.Builder its different from popup. but its a good way around. – grv_9098 Jul 17 '12 at 10:58
1
yes its possible. you need to design your custom layout and call that layout in popup window
For suppose this is my pop up code.
private void showPopUp()
{
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
helpBuilder.setTitle("");
LayoutInflater inflater = getLayoutInflater();
final View PopupLayout = inflater.inflate(R.layout.jobselection, null);
helpBuilder.setView(PopupLayout);
final AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
spn = (Spinner)PopupLayout.findViewById(R.id.spn);
caneclbtn = (ImageButton)PopupLayout.findViewById(R.id.cancelBtn);
selectallbtn = (ImageButton)PopupLayout.findViewById(R.id.selectBtn);
clearallbtn = (ImageButton)PopupLayout.findViewById(R.id.clearallBtn);
jobentries = (Button)PopupLayout.findViewById(R.id.entries);
jobList = (ListView)PopupLayout.findViewById(R.id.list);
//ur code here. You can add your spineer with items.
}
In this block you can write what you require. good luck
Ram kiran Pachigolla
- 20,897
- 15
- 57
- 78
-
-
thanks for your answer. this works fine but the dialog size is limited. is it possible to change the size of dialog? – Raneez Ahmed Jul 17 '12 at 10:37
-
there is a facility in android that we can show any page as dialog. so first of all create page in and add android:theme="@android:style/Theme.Dialog" in manifest to that activity. and then it will big size. – Ram kiran Pachigolla Jul 17 '12 at 10:39
-
In this config, how do you setup the listener--especially for the spinner and the OK button? – Quasaur Feb 10 '13 at 23:16
0
Better to use dialog (android.app.Dialog) to implement AutoCompleteTextView. In my opinion it's not possible to add AutoCompleteTextView in PopupWindow (you will get an exception). You can add Spinner in PopupWindow. You can implement both if you are using dialog instead of popup.
Nathan Tuggy
- 2,237
- 27
- 30
- 38
Jinosh P
- 341
- 2
- 8