0

I am trying to set PopupWindow in my app and it does not pop up.

Here is my code:

popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
                popUp.update(50, 50, 300, 200);
                layout.setOrientation(LinearLayout.VERTICAL);
                tv.setText("Hi this is a sample text for popup window");
                tv.setTextColor(Color.BLACK);
                params= new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);          
                layout.setOrientation(LinearLayout.VERTICAL);
                layout.addView(tv,params);
                layout.addView(cl);
                layout.addView(stats);
                layout.setBackgroundColor(Color.BLUE);
                main.findViewById(R.layout.ajax);
                mainLayout.addView(check,params);                   
                popUp.setContentView(layout);
                // popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
                setContentView(mainLayout);

What do I need to do to get this work and get a PopupWindow?

Thank You.

frogatto
  • 28,539
  • 11
  • 83
  • 129
  • You may want to consider using AlertDialog(.Builder). See http://developer.android.com/guide/topics/ui/dialogs.html – velis Mar 17 '14 at 14:28
  • I tried the AlertDialog but I need the PopupWindow that is perfect for my app. can you help me setting the PopupWindow? – Omer Malka Mar 17 '14 at 14:36
  • http://stackoverflow.com/questions/1967863/is-there-a-simple-example-of-the-popupwindow-class-using-android-v2-0 – velis Mar 17 '14 at 14:44
  • I am trying what you gave me in the link but "this.getSystem.Service" does not exist... what should I do? – Omer Malka Mar 17 '14 at 14:58
  • this is my code now: `inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); popUp=new PopupWindow(inflater.inflate(R.layout.popup, null,false),100,100,true); popUp.showAtLocation(findViewById(R.layout.ajax), Gravity.BOTTOM, 0, 0);` but it still doesn't work. (R.layout.ajax is the xml of the Activity and R.layout.popup is the xml for the popup). – Omer Malka Mar 17 '14 at 15:28
  • Does your layout.popup render in the visual form designer? – velis Mar 17 '14 at 16:29
  • Try implementing the example in that question and only then slowly modify it to finally end up with what you want. That way you'll know where the issue lies – velis Mar 17 '14 at 16:30
  • Do I need to initialize the context when I write `context.get...`? if yes to what? `Context context=null;`? – Omer Malka Mar 17 '14 at 17:33
  • context == your activity – velis Mar 17 '14 at 17:41
  • I tried coding it in other project and I am getting error about the context (the same code with the changes to the project). "context cannot be resolved" – Omer Malka Mar 17 '14 at 17:59
  • It would seem you are very new to Android development. I will say again: don't try to instantiate context. Use either your activity or your service as the context variable for any function calls that require context. – velis Mar 17 '14 at 19:22
  • I can't fix it. my code: `TVajax.setText(show); TVajax.setTextColor(Color.RED); LayoutInflater inflater = (LayoutInflater) Ajax.this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); PopupWindow pw = new PopupWindow( inflater.inflate(R.layout.popup, null, false), 100,100,true); pw.showAtLocation(Ajax.this.findViewById(R.layout.ajax), Gravity.CENTER, 0, 0); ` the first 2 lines work,the other not working. – Omer Malka Mar 18 '14 at 17:36
  • What's Ajax.this.context supposed to mean? Where is this function of yours? Again: context == activity, so unless you use fragments, just use getSystemService / findViewById, without Ajax.this.context. – velis Mar 19 '14 at 15:01
  • ok now I have the same code without the `Ajax.this.context.` but still the PopupWindow not displayed in my app. – Omer Malka Mar 19 '14 at 17:47

0 Answers0