1

我有一个片段工作正常的应用程序,

现在我需要实现一些弹出视图,

我正在关注本教程使用 PopupWindow 的示例

一切似乎都很好,但弹出窗口尚未显示,因为我对如何显示“popupWindow”有疑问

我的.java

public class Tab2HeadH1 extends Fragment implements OnClickListener {

   //testeo popero

   @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);  //old errors
                LayoutInflater layoutInflater = (LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                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()) {

       }
    }


}

那么显示我的弹出窗口缺少什么?

多谢!

4

3 回答 3

2

如果要生成自定义弹出窗口,可以使用 AlertDialog.Builder

private AlertDialog.Builder scheduleBuilder;
private AlertDialog dialog_Creater;

LayoutInflater myLayoutInflater = getLayoutInflater();
View v = myLayoutInflater.inflate(R.layout.schedule_creator, null); //Replace your layout R.layout.youLayout
            scheduleBuilder = new AlertDialog.Builder(v.getContext());


            scheduleBuilder.setTitle("Edit your Schedule Memo");
            scheduleBuilder.setView(v); //set view 



            dialog_Creater = scheduleBuilder.create();
            dialog_Creater.show();
于 2012-08-01T07:58:15.533 回答
1

尝试这个:-

PopupWindow pw;

View layout = inflater.inflate(R.layout.popnumber,
                (ViewGroup) findViewById(R.id.lytpopuppoppop));

// your popup layout  and  id of root layout 

pw = new PopupWindow(layout, LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT, true);
// your main layout where you display popup
pw.showAtLocation(findViewById(R.id.lytboard), Gravity.CENTER,
                        0, 0);
于 2012-08-01T07:54:09.917 回答
1

当您设置 Popup 时,您实际上并没有调用任何方法在任何地方显示它。调用以下任何一种方法适合您的需要打开它:

  1. 显示位置()
  2. showAsDropDown()
  3. showAsDropDown() (不同于#2)
于 2012-08-01T07:53:18.973 回答