2017-09-06 30 views
0

我想檢查在imageview圖像是否被選中或未被對於我已經使用真棒驗證來驗證的ImageView

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    if(requestCode==REQUEST_PICK_IMAGE && resultCode==RESULT_OK){ 

     path = data.getStringExtra(Constants.path); 

     isImageSet=true; 

     File imgFile=new File(path); 
     path =imgFile.getPath(); 

     Glide.clear(ivIdProof); 

     bitmap = BitmapFactory.decodeFile(path); 
     bitmap= ImageHandling.loadBitmapFromFile(this, path,400,400); 
     ivIdProof.setImageBitmap(bitmap); 

    } 

    super.onActivityResult(requestCode, resultCode, data); 


} 

真棒驗證代碼

awesomeValidation.addValidation(this, R.id.etIdentity, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", R.string.error_id1); 
awesomeValidation.addValidation(this, R.id.etIdentityNumber, "^[A-Za-z0-9\\s]{1,}[\\.]{0,1}[A-Za-z0-9\\s]{0,}$", R.string.error_id2); 

並檢查

if(awesomeValidation.validate() && path!=null){ 
..... 
} 

awesomeValidation.validate()用於驗證其他領域。 我如何使用真棒驗證並顯示錯誤消息

回答

0

檢查path!=null試試這個:

awesomeValidation.addValidation(this, R.id.your_view_id, "^null|$", R.string.error_your_id); 
+0

雖然此代碼片段可能會解決問題,但它並不能解釋爲什麼或如何回答問題。請包含您的代碼的說明,因爲這有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議 –

+0

的原因,謝謝@BalagurunathanMarimuthu,但是我想檢查path!= null'條件,其中路徑是字符串變量。如果路徑爲空或空值,則使用真棒驗證顯示錯誤消息。 –

0

您可以嘗試以下操作:

private boolean isImagePathValid(String path) { 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds =true; 
    Bitmap bitmap = BitmapFactory.decodeFile(path, options); 
    if(options.outWidth !=-1&&options.outHeight !=-1) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

現在從您的代碼:

if(awesomeValidation.validate() && isImagePathValid){ 

..... }