2017-09-06 63 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){ 

..... }