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

たぶん、あなたはあなたがAlertDialog.Builderを使用して同じ結果を得ることができます

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

Hey duanhong169、ありがとうございました。私はあなたが私のようなものだと信じることができると思う...私はそれを見ていない..ありがとう! =) –

0

を使用する必要がありますありがとうございました。次のコードを使用して、ポップアップを表示するには、次に

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(); 
} 
} 

:ここでは、2つのボタンでポップアップを表示するサンプルコードでは、カスタムビューを膨らませるしたい場合

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

こんにちはLev G. あなたの答えをありがとう。私はちょうど2つの単語を変更し、それが働いた、第2のものを見たので、あなたの答えを試していない、とにかくあなたに感謝:) –