0

i have created a button in android and when clicking it would show the popup window..but the code doesnot work like that..it has no errors but not showing popup window...please helpme..here is my code public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RelativeLayout objrl = (RelativeLayout) findViewById(R.id.myrl);      
    final Button objButton = (Button) findViewById(R.id.mybutton);
    objButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupWindow objPopupWindow = new PopupWindow(objrl, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);                
            objPopupWindow.setAnimationStyle(R.drawable.background2);
            objPopupWindow.showAtLocation(objButton, Gravity.CENTER_HORIZONTAL, 10, 10);
        }
    });

}
frogatto
  • 28,539
  • 11
  • 83
  • 129
CATIEEE
  • 45
  • 1
  • 9

4 Answers4

0

have you tried this : objPopupWindow.showAsDropDown(popupButton, 0, 0);

or try this http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html

0
 PopupWindow popupWindowDogs = popupWindowDogs();

called below function where they want ::-





 public PopupWindow popupWindowDogs() {

        // initialize a pop up window type
        PopupWindow popupWindow = new PopupWindow(this);

        // the drop down list is a list view
        ListView listViewDogs = new ListView(this);

        // set our adapter and pass our pop up window contents
        listViewDogs.setAdapter(dogsAdapter(popUpContents));

        // set the item click listener
        listViewDogs.setOnItemClickListener(new DogsDropdownOnItemClickListener());

        // some other visual settings
        popupWindow.setFocusable(true);
        popupWindow.setWidth(250);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

        // set the list view as pop up window content
        popupWindow.setContentView(listViewDogs);

        return popupWindow;
    }
Dakshesh Khatri
  • 639
  • 7
  • 12
0

I've found some strange stuff in your codes

  • You've specified WRAP_CONTENT but haven't specified its content at all
  • Pass a drawable as animation style to the setAnimationStyle method.

In my opinion if you specify a valid animation style and a content view, It should appear.

frogatto
  • 28,539
  • 11
  • 83
  • 129
  • @YurekaMathammalRajendran You shouldn't pass a drawble to that method. Also specify a content view for it by `setContentView` – frogatto Sep 01 '14 at 05:18
0

I think you missed this code inside the OnClickListener objPopupWindow.setContentView(objrl);

Pratheesh
  • 764
  • 1
  • 11
  • 24