我有一个 onLongClickListener 在调用时会重置一些值。我想添加一个 alertDialog 来检查用户是否真的想要重置所有值。但是,我不喜欢让它工作。
重置部分本身可以正常工作,但如果我尝试添加 AlertDialog 我会收到以下错误:
此行有多个标记 - 构造函数 AlertDialog.Builder(new View.OnLongClickListener(){}) 未定义 - 行断点:SatFinder [line: 174] - onLongClick(View)
这到底是什么意思,我该如何解决?非常感谢。
下面是代码部分。请注意,警报在此示例中没有任何用处。在我克服上述错误后,我会改变它。
resetAll = new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("This is the alertbox!");
// set a positive/yes button and create a listener
alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "'Yes' button clicked", Toast.LENGTH_SHORT).show();
}
});
// set a negative/no button and create a listener
alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show();
}
});
alertbox.show();
// Resets all values and radio buttons
pos1_deg.setText("0.0");
pos2_deg.setText("0.0");
pos1_az.setText("0.0");
pos2_az.setText("0.0");
targetDeg.setText("0.0");
blurg.setText("----");
radio1.setChecked(false);
radio2.setChecked(false);
radio3.setChecked(false);
radio1E.setChecked(true);
radio2E.setChecked(true);
radio3E.setChecked(true);
Toast.makeText(getApplicationContext(),
"Reset", Toast.LENGTH_LONG).show();
return true;
}
};