문제

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