imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent("android.intent.action.GET_CONTENT"); intent.setType("image/*"); getRootFragment().startActivityForResult(intent, 1); } });
private Fragment getRootFragment() { Fragment fragment = getParentFragment(); while (fragment.getParentFragment() != null) { fragment = fragment.getParentFragment(); } return fragment; }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { Uri uri = data.getData(); // 注意此处不要直接调用 Glide.with(mCtx).load(path).into(imageView);否则,会无效 // 而是通过handler进行发送消息显示图片 if (uri != null) { Message message = Message.obtain(); message.obj = uri; handler.sendMes