2012-04-22 96 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

相關問題