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 :)

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top