Pramod Setlur
Pramod Setlur

Reputation: 811

onLongClick() should work only if condition is true

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

So, as you can see, inside the onLongClick(), I have a condition. Only if this condition turns out to be true, the onLongClick() should work. Basically I want the Listener function to be called only if the condition is true. How do I get to do this?

Upvotes: 1

Views: 183

Answers (3)

Amit kumar
Amit kumar

Reputation: 1605

may solve the your problm.you can change the Retrun type is "true".

Upvotes: 2

secretlm
secretlm

Reputation: 2361

You can try to use: setOnLongClickListener(null) if your condition is false, otherwise is your listener which you defined.

Upvotes: 1

deepak825
deepak825

Reputation: 432

What is the problem Cant Understand to it...

By the Way u may set the longclicklistener in the if loop...

if loop(true)

set on longclickListener

else nothing....

Upvotes: 0

Related Questions