How to create a popupWindow

Put your problem here if it does not fit any of the other categories.

How to create a popupWindow

Postby bins1984 » Mon Mar 10, 2008 9:54 am

Anybody know to create a pop up window..........presently i have a map view and a attribute button when ever i click on the attribute button i should have to display a transparent pop up Window on top of that map view.......and i need to display some content on top of that.............

for that i created a layout in xml with a text and call like this ................but not working....
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. View mMain =(View)findViewById(R.layout.main1);
  3.  
  4.                         PopupWindow mWindow = new PopupWindow(this.findViewById(R.layout.main1),10,10);        
  5.  
  6.               mWindow.show(this.findViewById(R.layout.main1), 10,10);
  7.  
  8.               mWindow.setFocusable(true);
  9.  
  10.               mWindow.update(20, 20,50,50);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



and this.findViewById()is showing error......i am accessing from main java file only......
if any body knows this or anybody tried please give some sample codes of give some guidelines/.....


thanks bins......
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Top

Postby plusminus » Mon Mar 10, 2008 9:35 pm

Hello bins,

you are probably supposed to use the id of Views, like [font=Lucida Console]R.id.myTextView[/font] or similar.

The constructur of PopupWindow takes a "contentView" as the first parameter.
[font=Lucida Console]PopupWindow.show(...)[/font] takes a "parent" as the first parameter.
You are passing the same values to it... think about that ;)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby bins1984 » Tue Mar 11, 2008 11:25 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public void onCreate(Bundle icicle) {
  2.  
  3.         super.onCreate(icicle);
  4.  
  5.      
  6.  
  7.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  8.  
  9.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_NO_STATUS_BAR ,
  10.  
  11.                        WindowManager.LayoutParams.FLAG_NO_STATUS_BAR);
  12.  
  13.          setContentView(R.layout.main);
  14.  
  15.  
  16.  
  17.        Button b=(Button)findViewById(R.id.mbutton);
  18.  
  19.    
  20.  
  21.         b.setOnClickListener(new View.OnClickListener(){
  22.  
  23.                    
  24.  
  25.            
  26.  
  27.                         public void onClick(View v){
  28.  
  29.                                 Button b=(Button)findViewById(R.id.mbutton);
  30.  
  31.                                 b.setText("CLICK");
  32.  
  33.                         //View vv =(View)findViewById(R.id.fst);
  34.  
  35.                         PopupWindow mwindow=new PopupWindow(100,100);
  36.  
  37.                 mwindow.show(v.findViewById(R.id.fst), 50, 50);
  38.  
  39.                 mwindow.setFocusable(true);
  40.  
  41.                 mwindow.update(20, 20,50,50);
  42.  
  43.                 mwindow.isShowing();
  44.  
  45.                 }
  46.  
  47.          });
  48.  
  49.            
  50.  
  51.    
  52.  
  53.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

}}




i tried with all the combination and according to parent and child but still...............not able to execute
and this pointer is not taking its showing error..if i use this pointer then i cant use findViewById();

please help....
by bins
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby bins1984 » Wed Mar 12, 2008 6:13 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class network extends Activity {
  2.  
  3.         PopupWindow pw = null;
  4.  
  5.     public void onCreate(Bundle icicle) {
  6.  
  7.         super.onCreate(icicle);
  8.  
  9.         setContentView(R.layout.main);
  10.  
  11.     }
  12.  
  13.  
  14.  
  15.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  16.  
  17.         pw = new PopupWindow(this.getViewInflate().inflate(R.layout.main1,null,null),0,0);
  18.  
  19.         pw.show(this.findViewById(R.id.xx), 20, 20);
  20.  
  21.         pw.update(50,50,300,400);
  22.  
  23.         return true;
  24.  
  25.     }
  26.  
  27.    
  28.  
  29. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



hi guys i got the solution .........insrted of findview by id we have to use the ViewInflate.....
and the layout shoud call by the id of the lay out.................



with regards bins
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby bins1984 » Fri Mar 14, 2008 12:18 pm

hi.....can any body know how to use

isFocusable()
isShowing()
setOnDismissListener(OnDismissListener onDismissListener)



if know give small example..........
thanks bins!
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby alonav » Sat Apr 12, 2008 4:26 pm

Hi,
I want to show an openning window for the application while it's loading data.
how can i show the window at top & at the same time load data to list view?
thnx
alon
alonav
Freshman
Freshman
 
Posts: 4
Joined: Fri Mar 07, 2008 5:42 pm

Top

Postby Andcoder » Fri Sep 18, 2009 6:02 pm

I recently came across this problem i mixed and matched the codes finally got it working best place to look for this implementation is android source code calendar module in class "calendarview"
http://www.ceveni.com/2009/09/popup-win ... ogram.html
i think almost all the implementations can be found in android source code, its my experince though...
Andcoder
Freshman
Freshman
 
Posts: 3
Joined: Thu Jun 25, 2009 4:49 am

Postby Zeba Momin » Sat Dec 05, 2009 9:13 am

hi all...
I have a function as follows:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void showpopup() {
  2.  
  3.                 System.out.println("showpopup called....");
  4.  
  5.                 LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  6.  
  7.                 View v = vi.inflate(R.layout.popup_info, null);
  8.  
  9.                 System.out.println("view created....");
  10.  
  11.                 Popup = new PopupWindow(v, 250, 200);
  12.  
  13.                 Popup.setOutsideTouchable(false);
  14.  
  15.                 System.out.println("popup created....++" + Popup);
  16.  
  17.                 Popup.showAtLocation(this.findViewById(R.id.btn_login), Gravity.CENTER,
  18.  
  19.                                 20, 20);
  20.  
  21.                 System.out.println("popup shown....");
  22.  
  23.                 Button btn = (Button) findViewById(R.id.btnOK);
  24.  
  25.                 System.out.println("got ok bttn...."+btn);
  26.  
  27.                 btn.setOnClickListener(okListener);            
  28.  
  29.         }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


I hav a button 'btnOK" in my popup_info.xml (which is shown as a popup window).
But i get the variable 'btn' from
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Button btn = (Button) findViewById(R.id.btnOK);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

as null... :(
Can sumone plzz help me wid dis?? Thank you
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Postby galbayard » Sun Jan 24, 2010 10:43 am

try use this
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Button btn = (Button) v.findViewById(R.id.btnOK);
  3.  
  4.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
galbayard
Freshman
Freshman
 
Posts: 5
Joined: Thu Dec 10, 2009 2:49 am

Postby bins1984 » Thu Mar 04, 2010 5:09 am

Create Popup windows.

Create a Xml layout which contains the view for Popup window Object.
use lay out inflater

[b]LayoutInflater inflater = context.getLayoutInflater();
View mView= inflater.inflate(R.layout.xmla name,(ViewGroup)findViewById(R.id.LayoutId));

parametrs:first give the XMl file name
second give the Parent layout id of that xmal file.



Now create a poupwindow object
popupwindow mPopupWindow = new pupWindow(mView,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, false);
mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);

Get the main view lay out..means the activity holds one lay out file in
setcontentView(R.Layout.somelayout);

mLayout=(someViewtype)this.findViewById(R.id.MainlayoutId of someLayout.xml);


mPopupWindow.showAtLocation(mLayout, Gravity.CENTER, 0, 0);
[/b]
hope this can help..Cheers
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby bins1984 » Thu Mar 04, 2010 6:11 am

Create Popup windows.

Create a Xml layout which contains the view for Popup window Object.
use lay out inflater

LayoutInflater inflater = context.getLayoutInflater();
View mView= inflater.inflate(R.layout.xmla name,(ViewGroup)findViewById(R.id.LayoutId));

parametrs:first give the XMl file name
second give the Parent layout id of that xmal file.


Now create a poupwindow object
popupwindow mPopupWindow = new pupWindow(mView,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, false);
mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);

Get the main view lay out..means the activity holds one lay out file in
setcontentView(R.Layout.somelayout);

mLayout=(someViewtype)this.findViewById(R.id.MainlayoutId of someLayout.xml);


mPopupWindow.showAtLocation(mLayout, Gravity.CENTER, 0, 0);

hope this can help..Cheers
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby joby.nk » Thu Mar 04, 2010 7:21 am

Hi binil,

i am trying create a Popup window as per your code but its not working , its throw an error android.view.window manager$ bad token Exception. My code snippets are pasted below.Pls give me a solution

******popup.xml ******


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.  xmlns:android="http://schemas.android.com/apk/res/android"
  4.  android:layout_width="wrap_content" android:id="@+id/lnparentpopup"
  5.  android:layout_height="fill_parent" >
  6.  
  7.  
  8.  
  9.   <LinearLayout  
  10.                 android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/lncontainerpopup"
  11.                 android:orientation="horizontal" android:background="@drawable/top_blue_strip_bg">
  12.                
  13.                
  14.                         <TextView android:id="@+id/txtpopup" android:text="@string/scorecard_off_msg"
  15.                         android:layout_width ="200dip" android:layout_height="wrap_content" android:layout_marginRight="5dip" />
  16.                
  17.  
  18.  
  19.   </LinearLayout>
  20.  
  21. </LinearLayout>
  22.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4



***********main.xml***************

[align=right] <?xml version="1.0" encoding="utf-8"?>
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout
  2.  xmlns:android="http://schemas.android.com/apk/res/android"
  3.  android:layout_width="fill_parent" android:orientation="vertical"
  4.  android:layout_height="fill_parent"
  5.  android:id="@+id/lnparent">
  6.  
  7.         <TableLayout android:layout_width="fill_parent"   android:layout_weight=".7"
  8.                 android:id="@+id/tblntarialview"
  9.                         android:layout_height="wrap_content" android:gravity="center">
  10.                   <TableRow
  11.                         android:layout_width="wrap_content" android:paddingTop="15dip"
  12.                         android:gravity="center" android:layout_height="wrap_content">
  13.                        
  14.                         <TextView  android:text="No aerial view available for this hole !" android:textColor="@color/white"
  15.                         android:textSize="16dip" android:textStyle="bold" android:layout_width="fill_parent" android:id="@+id/txtmain"
  16.                          android:layout_height="wrap_content" android:layout_marginRight="5dip" />             
  17.                        
  18.                 </TableRow>
  19.         </TableLayout>
  20.        
  21.  
  22. </LinearLayout>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
[/align]

[b]


***********Activity class**************


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GreenScreen extends Activity {
  2.        
  3.     @Override
  4.     public void onCreate(Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.         setContentView(R.layout.main);
  7.        
  8.         showpopup();
  9.     }
  10.    
  11.    
  12.        private void showpopup()
  13.        {
  14.           LayoutInflater inflater = this.getLayoutInflater();
  15.           View mView= inflater.inflate(R.layout.popup,(ViewGroup)findViewById(R.id.lnparentpopup));
  16.           PopupWindow mPopupWindow = new PopupWindow(mView,LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT, false);
  17.           mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
  18.          
  19.           TextView TV=(TextView)this.findViewById(R.id.txtmain);          
  20.          // TableLayout L1 = (TableLayout)findViewById(R.id.tblntarialview);
  21.          
  22.           mPopupWindow.showAtLocation(TV, Gravity.CENTER, 0, 0);
  23.        
  24.         }
  25. }
  26.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4




joby.nk
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 29, 2009 1:22 pm
Location: INDIA

Postby bins1984 » Thu Mar 04, 2010 7:53 am

this cde will work chage activity class....


call showpopup() in some Event lister....

instead of calling in dirct from oncreate
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby joby.nk » Thu Mar 04, 2010 7:59 am

ya i got it.........Thax..
joby.nk
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 29, 2009 1:22 pm
Location: INDIA

Re: How to create a popupWindow

Postby aptgopal » Fri Dec 10, 2010 3:54 pm

Hi Bins
Is their any possibility to view each window at the same time that means main window and pop up window
aptgopal
Developer
Developer
 
Posts: 25
Joined: Tue Nov 16, 2010 7:08 pm
Location: India

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 11 guests