我有一個使用片段的應用程序,它的工作確定, 但我現在要實現一些彈出窗口當按鈕被竊聽,的Android PopupWindow
我下面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()) {
}
}
}
那麼,我該如何解決這個問題??,在我的片段中顯示我的彈出按鈕?
嗨,謝謝,我現在有LayoutInflater layoutInflater =(LayoutInflater)getActivity()。getBaseContext()。getSystemService(LAYOUT_INFLATER_SERVICE); ,,但我得到這個錯誤:LAYOUT_INFLATER_SERVICE無法解析爲 變量,請問如何解決這個問題?謝謝! – MaKo 2012-08-01 07:24:38
實際上你是從片段調用它並且它需要來自活動的上下文,所以它不會識別這些服務。它得到的上下文它運作良好。 – Android 2012-08-01 07:28:05