objImageButton.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
if(checkDiscrepancySubmitted(final_position))
{
// TODO Auto-generated method stub
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FragmentActivity.this);
alertDialogBuilder
.setMessage("Do you wish to delete the logged defect ?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int id)
{
int idButton=objImageButton.getId();
EditText objNewEditText=(EditText) findViewById(idButton);
objNewEditText.setTextColor(R.color.blue);
removeDefect(final_position,idButton,objNewEditText);
Toast.makeText(FragmentActivity.this, "Unsaved defects deleted.", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
return false;
}
return false;
}
});
因此,如您所见,在 内部onLongClick()
,我有一个条件。只有当这个条件成立时,onLongClick() 才能工作。基本上,我希望仅在条件为真时才调用 Listener 函数。我该怎么做?