但是当按下按钮时,我现在要实现一些d出窗口,
我跟随this tutorial “Example of using PopupWindow”
但我得到这个错误:
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(){}
在这里我的.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()) { } }}
那么,我怎么能解决这个问题??,从我的片段中点击按钮显示我的d出窗口?
解决方法 呼叫LayoutInflater layoutInflater =(LayoutInflater)** getActivity()**.getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
至少它不会显示错误onBaseContext(),因为它现在从关联的活动中获取
编辑
试试这个,
LayoutInflater layoutInflater =(LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
总结以上是内存溢出为你收集整理的来自片段的android PopupWindow全部内容,希望文章能够帮你解决来自片段的android PopupWindow所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)