我正在使用“警报”对话框获取用户团队图片的图像,然后我想在已打开的对话框上显示图像预览。
我正在将图像文件传递到我的对话框显示的那个片段,但我如何更新对话框中的ImageView
我试图更新适配器,通过该适配器我可以通知数据,但我仍然得到null适配器打电话给那个片段
public void passingImage(Image image) {
testAdapter.notifyImage(image);
}
这是我的警报对话框代码
public void showDialogForTeam(ChallengeData mData) {
this.mData = mData;
dialogForTeam = new Dialog(activity);
dialogForTeam.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogForTeam.setContentView(R.layout.dialog_team_selection);
dialogForTeam.setTitle("Select Team");
spinner = (Spinner) dialogForTeam.findViewById(R.id.spinner);
imgClose = (ImageView) dialogForTeam.findViewById(R.id.imageView);
RecyclerView.LayoutManager layoutManager5 = new LinearLayoutManager(getActivity());
rvLogo = (RecyclerView) dialogForTeam.findViewById(R.id.rv_logo);
rvLogo.setHasFixedSize(true);
rvLogo.setLayoutManager(layoutManager5);
rvLogo.setAdapter(testAdapter);
btnUpload = (TextView) dialogForTeam.findViewById(R.id.btn_upload_icon);
tealLogo = (ImageView) dialogForTeam.findViewById(R.id.team_logo);
btnUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int permissionCheck = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
openGallery();
} else {
Nammu.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, new PermissionCallback() {
@Override
public void permissionGranted() {
openGallery();
}
@Override
public void permissionRefused() {
}
});
}
}
});
GridView gridView = (GridView) dialogForTeam.findViewById(R.id.grid_view);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(activity, this));
Spinner spinner1 = (Spinner) dialogForTeam.findViewById(R.id.spinner1);
final LinearLayout llMyteam = (LinearLayout) dialogForTeam.findViewById(R.id.ll_m_team);
final RecyclerView recyclerViewTeam = (RecyclerView) dialogForTeam.findViewById(R.id.rv_team);
String[] strings = new String[0];
if (mData.getIsTeamcreater().equals("true")) {
strings = new String[]{"Join as Team Member", "Create Team"};
} else
strings = new String[]{"Join as Team Member"};
spinner.setAdapter(new ArrayAdapter<>(activity, R.layout.row_simple_text, strings));
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (parent.getItemAtPosition(position).toString().equals("Join as Team Member")) {
llMyteam.setVisibility(View.GONE);
recyclerViewTeam.setVisibility(View.VISIBLE);
} else {
llMyteam.setVisibility(View.VISIBLE);
recyclerViewTeam.setVisibility(View.GONE);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinner1.setAdapter(new ArrayAdapter<>(activity, R.layout.row_simple_text, strings));
if (mData.getTeams() != null && mData.getTeams().size() > 0) {
RecyclerView.LayoutManager layoutManager4 = new LinearLayoutManager(activity);
recyclerViewTeam.setHasFixedSize(true);
recyclerViewTeam.setLayoutManager(layoutManager4);
JoinTeamChallengeAdapter allTeamAdapter = new JoinTeamChallengeAdapter(activity, mData.getTeams(), this);
recyclerViewTeam.setAdapter(allTeamAdapter);
}
imgClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogForTeam.dismiss();
}
});
dialogForTeam.show();
}
public void openGallery() {
ImagePicker.create(activity)
.folderMode(true) // folder mode (false by default)
.folderTitle("Folder") // folder selection title
.imageTitle("Tap to select") // image selection title
.single() // single mode
.limit(1) // max images can be selected (99 by default)
.showCamera(true) // show camera or not (true by default)
.imageDirectory("Camera") // directory name for captured image ("Camera" folder by default)
.start(9686); // start image picker activity with request code
}
MianActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(TAG, "onActivityResult :" + requestCode);
if (requestCode == 9686) {
ArrayList<Image> images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
if (images.size() > 0 && images.size() == 1){
image = images.get(0);
mainHomeFragment.passingImage(image);
}
} else if (requestCode == 9687) {
ArrayList<Image> images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
if (images.size() > 0 && images.size() == 1)
onPhotoReturned(images.get(0));
}
super.onActivityResult(requestCode, resultCode, data);
}
答案 0 :(得分:0)
在Point下的Android Developer Page获取缩略图是一个示例,它显示了如何在使用Intent捕获它后在活动的现有ImageView中添加Photo。我希望这正是你要找的。 p>
修改强>
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
}
}
如您所见,您可以通过需要位图的setImageBitmap(image)
命令更改图像视图。如果这对您没有帮助,请尝试查看ImageView