2012-07-12 7 views
0

텍스트를 채우는 데이터베이스를 사용하여 작동하는 TextView가 있지만 로컬 데이터베이스에 이미지 경로 이름을 연결하고 싶습니다. 어떻게 이것을 java에 통합 할 수 있습니까? 주요 활동에서SQLite의 드로어 블 이미지 android

내가 설정하고 다음 질문에

String image = currentQ.getImage(); 
ImageView iView = (ImageView) findViewById(R.id.IS); 
Bitmap bMap = BitmapFactory.decodeFile(image); 
iView.setImageBitmap(bMap); 

:

file.path.name/drawable/i1.jpg and so on for the others. 

방법 :

private String image; 

/** 
* @return the image 
*/ 
public String getImage() { 
return image; 
} 
/** 
* @param image the image to set 
*/ 
public void setImage(String image) { 
this.image = image; 
} 

그리고 데이터베이스에 내가 텍스트로 선언하고

데이터베이스의 각 질문에 대해 드로어 블 폴더에 이미지 파일 위치를 첨부하고 자바에 연결할 수 있습니까? 사전에

감사합니다.

+0

드로어 블 폴더의 이미지는 그 ID (예 : R.drawable.imageName)를 통해서만 참조 할 수 있습니다. 정적 경로를 원하면 다른 것을해야합니다. 즉, 자산 폴더에 저장 한 다음 원시 자산으로 추출합니다. – Jug6ernaut

+0

어떻게이 작업을 수행 할 수 있습니까? 그리고 데이터베이스에 경로를 넣는 아이디어에 대해 - 내가 선택한 대답이 다음 질문으로 이동하고 이미지가 텍스트에 첨부되어 있습니까? – KSG

+0

몇 개의 이미지가 있습니까? – Jug6ernaut

답변

0
ImageView imageView = (ImageView) findViewById(R.id.imageView); 

String imageName = "NameofImage"; // store only image name in database(means not store "R.drawable.image") like "image". 
      int id = getResources().getIdentifier("projectPackageName:drawable/" + imageName, null, null); 
      imageView.setImageResource(id); 
+0

답을 설명해주세요. –

관련 문제