2013-01-07 4 views
1
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()이 작동해야합니다. 기본적으로 조건이 true 인 경우에만 Listener 함수가 호출되기를 원합니다. 어떻게해야합니까?onLongClick()은 조건이 true 인 경우에만 작동해야합니다.

답변

1

조건을 거짓으로 설정하면 setOnLongClickListener(null)을 사용할 수 있습니다. 그렇지 않으면 정의한 청취자가됩니다.

0

그런데 칸트는 그것을 이해 문제 ...

... u는 경우 루프에서 longclicklistener를 설정할 수 있습니다 무엇입니까 경우 (참)

set on longclickListener 

루프 else nothing ....

+0

이렇게하면 onLongClick()이 전혀 작동하지 않습니다. –

2

당신의 problm.you를 해결할 수 있습니다 Retrun 유형을 변경할 수 있습니다 "사실"입니다.

관련 문제