Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了来自片段的android PopupWindow大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_6@ 我有一个使用片段的应用程序,它工作正常,
但是当按下按钮时,我现在要实现一些弹出窗口,

我跟随this tutorial “Example of using PopupWindow”

但我得到这个错误

@H_856_11@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(){}

@L_607_5@我的.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,@R_944_6633@  
                        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()) {



        }
    }


}

那么,我怎么能解决这个问题??,从我的片段中点击按钮显示我的弹出窗口?

解决方法

呼叫

LayoutInflater layoutInflater =(LayoutInflater)** getActivity()**.getBaseContext().getSystemservice(LAYOUT_INFLATER_serviCE);

至少它不会显示错误onBaseContext(),因为它现在从关联的活动中@L_874_14@

编辑

试试这个,

LayoutInflater layoutInflater =(LayoutInflater)getActivity().getBaseContext().getSystemservice(Context.LAYOUT_INFLATER_serviCE);

大佬总结

以上是大佬教程为你收集整理的来自片段的android PopupWindow全部内容,希望文章能够帮你解决来自片段的android PopupWindow所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。