메인 액티비티
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
File file = new File(path.get(position));
String filename = file.getName();
String ext = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
if (ext.equals("JPG") || ext.equals("jpg")) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("totalpath", file.getPath());
intent.putExtras(bundle);
intent.setClass(PoemList.this, PoemClicked.class);
startActivityForResult(intent, 0);
}
서브 액티비티
setContentView(R.layout.select_image);
TextView txtImgName = (TextView)findViewById(R.id.jpgname);
ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
//jpgView.setOnClickListener(clickListener);
Intent intent = getIntent();
if(intent!=null){
String path = intent.getStringExtra("totalpath");
txtImgName.setText(path);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm = BitmapFactory.decodeFile(path, options);
jpgView.setImageBitmap(bm);
레이아웃 파일
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/jpgname"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:id="@+id/jpgview"/>
</LinearLayout>
전체설명
이미지를 ImageView 에 표현하기 위해 Bitmap 객체로
디코딩하고 ImageView 의 setImageBitmap() 함수에
인수로 넘겨 화면에 표현하는데 막상 실행해보면
텍스트뷰에서만 출력되고 이미지뷰는 출력되지않는 문제가 발생합니다.
메인 액티비티에 문제인지
서브 액티비티에 문제인지
레이아웃에 문제인지 모르겠습니다.