Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java – PopupWindow in OnCreate with ShowAtLocation- how to get Parent View?

Posted on November 11, 2022 By

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

READ  [FIXED] android - Add rounded corners to images
Powered by Inline Related Posts
Android Tags:android, android-studio, java, popupwindow

Post navigation

Previous Post: [FIXED] android – how to change notification background color in nougat?
Next Post: [FIXED] android – How to make width ratio equal in XML GridView

Related Posts

[FIXED] android – D8: Cannot fit requested classes in a single dex file Android
[FIXED] android – How can i see The full Inner Working of an OkHttp Client? Retrofit Socket Closed Time Out Android
[FIXED] java – Application keeps crashing when I try to load the database Android
[FIXED] android – Where is the supportFragmentManager variable defined? Android
[FIXED] This is my first Android program using Java, I am trying to use a alert dialog, but the app keeps on closing Android
[FIXED] dart – Conditional Rendering of Widgets Flutter Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme