PDA

View Full Version : help needed to show popup window...


nitin2304
08-06-2009, 02:05 AM
hello,

I want to show a LinearLayout (with other controls in it) as popup window on a button-click, could some one pls HELP me to solve it.....I googled but no luck.

many thanks in advance
Nitin

Andcoder
09-18-2009, 12:14 PM
Best Place to look for solution is android source code i recently wanted to implement popup window and after long search on web i found solution in android calendar module source code in "calendarview" class in "updateeventdetails" method her is my experience http://www.ceveni.com/2009/09/popup-window-in-android-sample-program.html

arnodenhond
09-22-2009, 09:51 PM
First inflate your layout.xml and assign it to a ViewGroup.
Prepare the controls in the viewgroup. (fe. assign OnClickListeners)

Personally I like to use AlertDialog.Builder to build a new alert dialog.
Use the setView method to assign your layout/viewgroup to the dialog.
Don't forget to call the create method.

Best to do all of this in the Activity's onCreateDialog method

@Override
protected Dialog onCreateDialog(int id) {
//inflate layout
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
ViewGroup aboutview = (ViewGroup) inflater.inflate(R.layout.about, null);
//prepare controls
Button button = (Button) aboutview.findViewById(R.id.button);
siteButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//add code here..
}
});
//create alert dialog with layout assigned as view
return new AlertDialog.Builder(this).setView(aboutview).creat e();
}If you want to use a normal Dialog, use the setContentView method.

To open the dialog just call the Activity's showDialog method from your button click handling code.