android PopupWindow from a fragment

15,327

call

LayoutInflater layoutInflater = (LayoutInflater)**getActivity()**.getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);

Atleast it won't show error onBaseContext() as now it take from the associated activity

EDIT

Try this,

LayoutInflater layoutInflater = (LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

Share:
15,327
manuelBetancurt
Author by

manuelBetancurt

Computers, BJJ, Open Source, Psichotronics "Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile", "Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgment difficult." Hippocrates "Hay cosas tan grandes y complejas que solo el hombre indicado o un loco se atreven a afrontar!!", "There are things so great and complex that only the right man or a nut case dare to face!!" Don Juan

Updated on June 21, 2022

Comments

  • manuelBetancurt
    manuelBetancurt almost 2 years

    I have an app that uses fragments, its working ok, but I have now to implement some pop ups when a button gets tapped,

    I am following this tutorial "Example of using PopupWindow"

    But I get this errors:

    Multiple markers at this line
        - LAYOUT_INFLATER_SERVICE cannot be resolved to a variable
        - The method getBaseContext() is undefined for the type new 
         View.OnClickListener(){}
    

    here my .java

    public class Tab2HeadH1 extends Fragment   implements OnClickListener{
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
    
            View view = inflater.inflate(R.layout.tab_2_head_buttons, container,false);
    
            //Buttons
    
            Button buttonNose = (Button) view.findViewById(R.id.button_pop_nose);
    
            buttonNose.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View v) {
                  //aqui tus tareas,,
    
                    LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  //ERRORS HERE!!
    
                   View popupView = layoutInflater.inflate(R.layout.popup, null);  
                            final PopupWindow popupWindow = new PopupWindow(
                              popupView, 
                              LayoutParams.WRAP_CONTENT,  
                                    LayoutParams.WRAP_CONTENT);
    
                }
    
    
            });
    
    
            Button buttonEye = (Button) view.findViewById(R.id.button_pop_eye);
    
            buttonEye.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(final View v) {
                   // onLoginClicked(v);
                    Toast.makeText(getActivity(), "ss9 eye",
                            Toast.LENGTH_SHORT).show();
    
                }
            });
    
    return view;
        }
    
    
    
        @Override
        public void onViewCreated(View view, Bundle savedInstanceState) {
    
            super.onViewCreated(view, savedInstanceState);
    
    
    
            ((TabActivity)getActivity()).setHeader("TAPING APPLICATION");
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
    
    
    
            }
        }
    
    
    }
    

    SO, how can I fix this problem??, to show my pop up from tapped button in my fragment??