我试图在 onTouchListener 内显示警报,但无法显示。我对此很陌生,但我一直在关注一些好的教程,但无济于事。这是代码的一部分...任何想法为什么此警报不会显示?
mSwitcher.setOnTouchListener(new OnTouchListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
}
@Override public boolean onTouch(View v, MotionEvent event)
{
// the attempt at the alert
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alert = builder.create();
return false;
}
});
我认为我的结构还可以,但我什至无法编译。