之前我发过这个问题,但我删除了它,因为我要粘贴更多代码。
我的问题是我在点击时有一个PopupUpWindow,并出现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 :(得分:0)
也许你应该使用
Button si=(Button) popUpView.findViewById(R.id.buttonyes);
Button no=(Button) popUpView.findViewById(R.id.buttonno);
答案 1 :(得分: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)