Solution 1 :
Replace
onboardPopupWindow.showAtLocation(this,Gravity.CENTER,0,0);
with
v.post(new Runnable() {
public void run() {
onboardPopupWindow.showAtLocation(v,Gravity.CENTER, 0, 0);
}
});
Problem :
I want to show my popupwindow in the middle of the screen. I’m calling it in OnCreate from the MainActivity. I cannot understand how I can get the parent view that showAtLocation is asking for :
public void showAtLocation(android.view.View parent, int gravity, int x, int y)
what I have is:
List<Fragment> list=new ArrayList<>();
list.add(new PageFragment1());
list.add(new PageFragment2());
list.add(new PageFragment3());
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.onboarding, null);
pager=v.findViewById(R.id.pager);
pagerAdapter=new Onboard_SlidePageAdapter(getSupportFragmentManager(),1,list);
pager.setAdapter(pagerAdapter);
onboardPopupWindow = new PopupWindow(v,500, RelativeLayout.LayoutParams.WRAP_CONTENT, true);
onboardPopupWindow.setElevation(10);
onboardPopupWindow.showAtLocation(this,Gravity.CENTER,0,0);
I’m aware that I cannot pass “this” but there is no this.getView() or similar