I found this tutorial on android which allows you to show a popup window see tutorial
But what I do is show my popupwindow without pressing any button, this is what I have:
private PopupWindow popupWindow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.conductor);
View rootView = getWindow().getDecorView().getRootView();
mostrar_popup(rootView);
}
private void mostrar_popup(View rootView) {
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate the custom popup layout
final View inflatedView = layoutInflater.inflate(R.layout.lista_alumnos, null,false);
// find the ListView in the popup layout
ListView lista_alumnos = (ListView)inflatedView.findViewById(R.id.lista_alumnos);
// get device size
Display display = getWindowManager().getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
// set height depends on the device size
popupWindow = new PopupWindow(inflatedView, size.x - 50,size.y - 400, true );
// set a background drawable with rounders corners
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.fondo_lista_alumnos));
// make it focusable to show the keyboard to enter in `EditText`
popupWindow.setFocusable(true);
// make it outside touchable to dismiss the popup window
popupWindow.setOutsideTouchable(true);
// show the popup at bottom of the screen and set some margin at bottom ie,
popupWindow.showAtLocation(rootView, Gravity.BOTTOM, 0,100); //aqui esta mi error
}
driver.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff" >
<fragment
android:id="@+id/map_conductor"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
I thank you in advance
If you do this from onCreate() you will probably get an error, since the root view is not fully created:
To make it work correctly calling the from method
onCreateView()
, add in your layout loaded bysetContentView()
an id, for example:the defined id is container, so you call the method like this:
According to your code it would be like this: