0

I have an activity and a class that implements a popup window. Using this tutorial I implemented the popup. I call the methods init() and popupInit() from the activity and everything else is in the class. My problem is that the popup does not show.

Here is the popup class:

public class PopupAudio implements OnClickListener {

    LinearLayout layoutOfPopup;
    PopupWindow popupMessage;
    Button popRecord, popStopRecord, popPlay, popStopPlaying;
    TextView popupText;

    public void popupInit() {
        popRecord.setOnClickListener(this);
        popStopRecord.setOnClickListener(this);
        popPlay.setOnClickListener(this);
        popStopPlaying.setOnClickListener(this);
        popupMessage = new PopupWindow(layoutOfPopup, LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        popupMessage.setContentView(layoutOfPopup);
    }

    public void init(Context context) {
        popRecord = new Button(context);
        popRecord.setId(112);
        popStopRecord = new Button(context);
        popPlay = new Button(context);
        popStopPlaying = new Button(context);
        layoutOfPopup = new LinearLayout(context);
        popRecord.setText("REC");
        layoutOfPopup.setOrientation(1);
        layoutOfPopup.addView(popRecord);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()) {
        case 112:

            break;
        }
    }

}

It is a school project so it is very important. Please help me, I'll be grateful :)

frogatto
  • 28,539
  • 11
  • 83
  • 129
user3132352
  • 403
  • 1
  • 9
  • 24
  • 1
    Do you call on of the **[variations](http://developer.android.com/reference/android/widget/PopupWindow.html#showAsDropDown(android.view.View))** of `popup.show()` somwhere – codeMagic Apr 14 '14 at 19:10
  • was just about to say, you might be missing your `.show()`. @codeMagic has it – john Apr 14 '14 at 19:10

1 Answers1

0

You need to call a method to actually show the popup on some event action or whenever you need it. Here are the different methods from the docs

Here is one example of using showAtLocation().

showAsDropDown(View anchor) may be the simplest depending on your needs. Just pass it the view you want it to attach to. Though, the other two give you more flexibility on where it shows.

Community
  • 1
  • 1
codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • I get the view from the activity using this: this.findViewById(R.layout.activity_note) And I use popupMessage.showAsDropDown(anchor); but it throws me nullpointer exception – user3132352 Apr 14 '14 at 19:26
  • You need to initialize your popupwindow somewhere. You do it in your other class but don't return the view so it's not initialized anywhere. In the tutorial you are following, they do it all in the activity class. – codeMagic Apr 14 '14 at 19:46