While clicking the popup button it’s not showing popup box and it’s force close the application. Here i included my code (xml and java) for my native android application.
popup.xml
<Button
android:id="@+id/ButtonPopup"
android:layout_marginTop="20dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonInPopup"
android:text="Dismiss this PopupWindow">
</Button>
Java code
public void onButtonPopup (View target) {
// Make a View from our XML file
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup,(ViewGroup) findViewById(R.id.ButtonPopup));
m_pw = new PopupWindow( layout, 350, 250, true);
m_pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
}
You are inflating
popup.xmland defined the parent as(ViewGroup) findViewById(R.id.ButtonPopup). This ViewGroup will not create until you inflate the layout. andfindViewByIdwill work only after you set the layout insetContentView.Try inflating using this –