2012-04-22 99 views
0

我以前发过这个问题,但我删除了它,因为我要粘贴更多的代码。PopUpWindow之后什么也没有发生

我的问题是我有一个PopupUpWindow点击和2个按钮时出现。所以,这2个按钮有OnClick,但没有任何反应。我要粘贴我的代码:

 // PopupWindow de Exit 

    Button exit=(Button) findViewById(R.id.button1); 
    popUpView = getLayoutInflater().inflate(R.layout.estadisticaspopupwindowexit, null); 
    mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true); 


    exit.setOnClickListener(new View.OnClickListener(){ 
     @Override 
     public void onClick(View v) { 
      System.out.println("no clicked");//For checking that it's ok 
      mpopup.showAtLocation(popUpView, Gravity.BOTTOM, 0, 0); 
      // UNTIL HERE IT'S OK 
      View viewexit = (LinearLayout) factory.inflate(R.layout.estadisticaspopupwindowexit, null); 
      Button si=(Button) viewexit.findViewById(R.id.buttonyes); 
      Button no=(Button) viewexit.findViewById(R.id.buttonno); 

      // THESE ARE BUTTONS CALLED FROM ANOTHER XML FILE 

      si.setOnClickListener(new View.OnClickListener(){     
       @Override 
       public void onClick(View v) { 
        Intent intencion=new Intent(estadisticas.this, datosusuario.class); 
        startActivity(intencion); 
       } 


      }); 
      no.setOnClickListener(new View.OnClickListener() { 
       public void onClick(View v){ 
        mpopup.dismiss(); 
        System.out.println("no clicked"); 
// I'M WRITING THE LAST THING FOR CHECKING ON MY LOGCAST IF IT REALLY WORKS, BUT NOTHING HAPPENS 

       } 
      }); 


     } 

    }); 

这就是一切。 谢谢

回答

0

也许你应该使用

Button si=(Button) popUpView.findViewById(R.id.buttonyes); 
Button no=(Button) popUpView.findViewById(R.id.buttonno); 
+0

嘿duanhong169,非常感谢。我想你可以相信我是一种盲人...我没有看到它..谢谢! =) – 2012-04-22 16:47:28

0

您可以通过使用AlertDialog.Builder达到同样的效果。下面是一个示例代码来显示一个弹出有两个按钮:

public class UIHelper { 
    public static void createInformationalAlert(Context context, 
     DialogInterface.OnClickListener positiveButtononClickListener, 
     DialogInterface.OnClickListener negativeButtononClickListener, 
     String content, String positiveButtonCaption, 
     String negativeButtonCaption) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(context); 
    builder.setMessage(content) 
      .setPositiveButton(positiveButtonCaption, 
        positiveButtononClickListener) 
      .setNegativeButton(negativeButtonCaption, negativeButtononClickListener); 
    AlertDialog alertDialog = builder.create(); 
    alertDialog.show(); 
} 
} 

然后,显示弹出,使用下面的代码:如果你想膨胀的自定义视图

UIHelper.createInformationalAlert(this, 
      new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        // TODO Auto-generated method stub 

       } 
      }, new DialogInterface.OnClickListener() { 

       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        // TODO Auto-generated method stub 

       } 
      }, "Are you sure you want to exit?", "Yes", "No"); 

,使用setView(View)

+0

Hi Lev G. 感谢您的回答。我没有尝试你的答案,因为我看到第二个改变了2个单词,它工作,反正谢谢:) – 2012-04-22 16:46:50