在我的应用程序中,用户必须上传一些附件才能完成注册。
我显示了一个附件清单。当用户点击某个项目时,我会启动一个意图从设备中选择一个文件。在onActivityResult
中,我在当前片段上调用setFileImage()
来更新复选框drawable。
问题是调用imageView.setImageResource
不起作用。我尝试用backgroudn替换ImageViews,然后使用imageView.setBackgroundResource
,但这也不起作用。
我完全不知所措,我真的可以使用一些帮助来调试这段代码:
RegistrationActivity.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Attachment attachment = pathFromActivityResult(requestCode, resultCode, data);
if(attachment == null){
return;
}
if (!TextUtils.isEmpty(attachment.getPath()) && !TextUtils.isEmpty(attachment.getMimeType())) {
switch (mCurrentFile) {
case RegisterStage5Fragment.COMMERCIAL_REGISTRATION_IMAGE:
mRegistration.setCommercial_registration_copy(attachment);
break;
case RegisterStage5Fragment.OWNER_NATIONAL_CARD_IMAGE:
mRegistration.setOwner_national_card_copy(attachment);
break;
case RegisterStage5Fragment.ACCREDITATION_IMAGE:
mRegistration.setAccreditation_file_copy(attachment);
break;
case RegisterStage5Fragment.CONTACT_NATIONAL_CARD_IMAGE:
mRegistration.setContact_national_card_copy(attachment);
break;
case RegisterStage5Fragment.BANK_INFORMATION_PROOF_IMAGE:
mRegistration.setBank_information_proof_copy(attachment);
break;
}
mRegisterStage5Fragment.setFileImage(mCurrentFile);
}
mCurrentFile = -1;
}
}
RegisterStage5Fragment.java
public class RegisterStage5Fragment extends BaseFragment {
public static final int COMMERCIAL_REGISTRATION_IMAGE = 1;
public static final int OWNER_NATIONAL_CARD_IMAGE = 2;
public static final int ACCREDITATION_IMAGE = 3;
public static final int CONTACT_NATIONAL_CARD_IMAGE = 4;
public static final int BANK_INFORMATION_PROOF_IMAGE = 5;
@InjectView(R.id.commercialRegistrationImage) View mCommercialRegistrationImage;
@InjectView(R.id.ownerNationalCardImage) View mOwnerNationalCardImage;
@InjectView(R.id.accreditationImage) View mAccreditationImage;
@InjectView(R.id.contactNationalCardImage) View mContactNationalCardImage;
@InjectView(R.id.bankInformationProofImage) View mBankInformationProofImage;
RegisterActivity mRegisterActivity;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View contentView = inflater.inflate(R.layout.fragment_register_stage_5, null, false);
ButterKnife.inject(this, contentView);
mRegisterActivity = (RegisterActivity) getActivity();
((RegisterActivity) getActivity()).setRegisterStage5Fragment(this);
return contentView;
}
public void setFileImage(int fileImage) {
switch (fileImage) {
case RegisterStage5Fragment.COMMERCIAL_REGISTRATION_IMAGE:
mCommercialRegistrationImage.setBackgroundResource(R.drawable.tick);
break;
case RegisterStage5Fragment.OWNER_NATIONAL_CARD_IMAGE:
mOwnerNationalCardImage.setBackgroundResource(R.drawable.tick);
break;
case RegisterStage5Fragment.ACCREDITATION_IMAGE:
mAccreditationImage.setBackgroundResource(R.drawable.tick);
break;
case RegisterStage5Fragment.CONTACT_NATIONAL_CARD_IMAGE:
mContactNationalCardImage.setBackgroundResource(R.drawable.tick);
break;
case RegisterStage5Fragment.BANK_INFORMATION_PROOF_IMAGE:
mBankInformationProofImage.setBackgroundResource(R.drawable.tick);
//mBankInformationProofImage.setImageDrawable(getResources().getDrawable(R.drawable.tick));
break;
}
}
}