Cómo crear una ventana emergente (PopupWindow) en Android

Para crear una ventana emergente de trabajo simple, necesitamos hacer lo siguiente:

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

pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);

Mi requisito es que necesito una

<TEXTVIEW android:layout_height="wrap_content" android:layout_width="fill_parent" />

y a

<BUTTON android:id="@+id/end_data_send_button" android:text="Cancel"/>

en mipopup_example.xml. ¿Cómo puedo manejar estos dos componentes en mi código Java?

Respuestas a la pregunta(7)

Su respuesta a la pregunta