0

I am getting the following exception, while trying to call this method.

Exception in MessageQueue callback: handleReceiveCallback 08-21 00:12:43.454 10843-10843/common.barter.com.barterapp E/MessageQueue-JNI﹕ android.view.InflateException: Binary XML file line #2: Error inflating class at android.view.LayoutInflater.createView(LayoutInflater.java:633) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365)

public class GlobalHome extends ActionBarActivity{
----------------------
----------------------
private void showLocationPopup() {

    LayoutInflater inflater = (LayoutInflater)
            this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popup_location,
            (ViewGroup) findViewById(R.id.layout_location_popup));
    PopupWindow pw = new PopupWindow(
            layout,
            100,
            100,
            true);
    // The code below assumes that the root container has an id called 'main'
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

}
}

Layout file

<?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"
android:background="@color/switch_thumb_material_light"
android:id="@+id/layout_location_popup"
>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:text="Test Pop-Up"
    />

</LinearLayout>
pagalpanda
  • 150
  • 2
  • 16

1 Answers1

0

Change your code to:

private void showLocationPopup() {

    LayoutInflater inflater = (LayoutInflater)
            getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popup_location,(ViewGroup) getActivity().findViewById(R.id.layout_location_popup));
    PopupWindow pw = new PopupWindow(
            layout,
            100,
            100,
            true);
    // The code below assumes that the root container has an id called 'main'
    pw.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

}

and

<?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"
android:background="#FFFFFF"
android:id="@+id/layout_location_popup">

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:text="Test Pop-Up"/>
</LinearLayout>

I've changed the colour, as the one you picked does not work. Seems not be a typical android colour to me. Further I've set the layout width and height to 'WRAP_CONTENT'. For me it shows up fine now in the middle of the screen with a white background.

Anytoe
  • 1,605
  • 1
  • 20
  • 26