【发布时间】:2014-08-29 03:31:45
【问题描述】:
我希望你能帮助我解决我的简单问题。我正在尝试从我的画廊中选择要在我的 Imageview 上显示的图像,它可以工作,但问题是,它在我关闭我的应用程序后消失了。请检查我在下面找到的代码。
iv=(ImageView) rootView.findViewById(R.id.profpic);
iv.setOnClickListener(this);
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(getActivity(), "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == Activity.RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
iv.setImageURI(uri);
Log.d(TAG, "File Uri: " + uri.toString());
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
还有我的 xml:
<ImageView
android:id="@+id/profpic"
android:layout_width="113dp"
android:layout_height="113dp"
android:paddingRight="1dp"
android:src="@drawable/propic" />
我是 android 开发的新手,我们将不胜感激。提前致谢!
【问题讨论】:
-
Activity被销毁,图片也被销毁
标签: android imageview filechooser