------

[ AD ] Port Monitor ( Try to use a Best WebSite Monitoring Tool )

------

http://stackoverflow.com/questions/1967863/is-there-a-simple-example-of-the-popupwindow-class-using-android-v2-0

 

 

I created a working example based on this Google Groups post.

To create a simple working PopupWindow, you'll need to do the following:

  1. Create a layout XML which describes the View that will be rendered within the PopupWindow.
  2. Invoke the PopupWindow by inflating the layout XML, and assign the appropriate "parent view" to the pop-up.

popup_example.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:padding="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
 
    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dip" 
        android:text="Test Pop-Up" 
    /> 
 
</LinearLayout> 

Java code:

    LayoutInflater inflater = (LayoutInflater) 
       this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    PopupWindow pw = new PopupWindow( 
       inflater.inflate(R.layout.popup_example, null, false),  
       100,  
       100,  
       true); 
    // The code below assumes that the root container has an id called 'main' 
    pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);  
 
 
 
http://rsequence.com/android_blog/node/160
private DismissPopup mDismissPopup = new DismissPopup();

if (mShowToast) {
    LayoutInflater inflater;
    inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mPopupView = inflater.inflate(R.layout.month_bubble, null);
    mPopup = new PopupWindow(activity);
    mPopup.setContentView(mPopupView);
    Resources.Theme dialogTheme = getResources().newTheme();
    dialogTheme.applyStyle(android.R.style.Theme_Dialog, true);
    TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] {
        android.R.attr.windowBackground });
    mPopup.setBackgroundDrawable(ta.getDrawable(0));
    ta.recycle();
}
        
        
if (mShowToast) {
    mPopup.dismiss();
    mPopup.setWidth(width - 20);
    mPopup.setHeight(POPUP_HEIGHT);
}
        
        
mPopup.setHeight(popupHeight);

if (mPreviousPopupHeight != popupHeight) {
    mPreviousPopupHeight = popupHeight;
    mPopup.dismiss();
}
mPopup.showAtLocation(this, Gravity.BOTTOM | Gravity.LEFT, 0, 0);
postDelayed(mDismissPopup, POPUP_DISMISS_DELAY);


class DismissPopup implements Runnable {
    public void run() {
        mPopup.dismiss();
    }
}

// This is called when the activity is paused so that the popup can
// be dismissed.
void dismissPopup() {
    if (!mShowToast) {
        return;
    }

    // Protect against null-pointer exceptions
    if (mPopup != null) {
        mPopup.dismiss();
    }

    Handler handler = getHandler();
    if (handler != null) {
        handler.removeCallbacks(mDismissPopup);
    }
}

+ Recent posts