2012-05-03 5 views
2

도움이 필요하십니까? 이상 할지도 모른다.새로운 활동으로 이미지를 열 수 없습니다

첫 번째 활동에는 목록보기가 있습니다 (예 : lazyadapter). 목록을 클릭하면 설명, 제목 및 이미지가 포함 된 새로운 활동이 열립니다. 그러나 iam은 이미지를 표시 할 수 없습니다.

public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 


String title = ((TextView) view.findViewById(R.id.title)).getText().toString(); 
String description = ((TextView) view.findViewById(R.id.artist)).getText().toString(); 
String pdate = ((TextView)view.findViewById(R.id.pdate)).getText().toString(); 
//ImageView thumb = ((ImageView) view.findViewById(R.id.list_image)); 

// Starting new intent 
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); 
    in.putExtra(KEY_PLAYER, title); 
    in.putExtra(KEY_THUMB_URL, R.id.list_image); 
    in.putExtra(KEY_TRANSACTION, description); 
    in.putExtra(KEY_PUBDATE, pdate); 
    startActivity(in); } 

제 2의 활동

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Intent in = getIntent(); 

    String title = in.getStringExtra(KEY_PLAYER); 
    String description = in.getStringExtra(KEY_TEXT); 
    String pdate = in.getStringExtra(KEY_PUBDATE); 
    String thumb_image = in.getStringExtra(KEY_THUMB_URL); 

    TextView lblName = (TextView) findViewById(R.id.name_label); 
    TextView lblDesc = (TextView) findViewById(R.id.description_label); 
    TextView lblPdate = (TextView) findViewById(R.id.pubdate_label); 
    ImageView thumb = (ImageView) findViewById(R.id.thumb_label); 

    lblName.setText(title); 
    thumb.setImageURI(Uri.parse(thumb_image)); 
    lblDesc.setText(description); 
    lblPdate.setText(pdate); 
+0

두 번째 활동의 자원에서 직접 이미지를 설정할 수 있습니까? 아니 getStringExtra에서 .. – Mihir

답변

0
int thumb_image = in.getIntExtra(KEY_THUMB_URL); 
thumb.setImageResource(thumb_image); 

당신은 당신의 의도에 자원 ID (정수)에 전달하는 ... 보낼 방법을 잘하지 않습니다. 당신이 그 의도를받을 때 R.id.list_image 값을 줄 수있는 getIntExtra을 사용하여 추출합니다. 그런 다음 ImageView에서 setImageResource으로 전화하여 이미지를 설정할 수 있습니다.

정수로 전달할 때 getStringExtra을 호출하면 null 문자열이됩니다.

+0

이 너무 작동해야합니다 ... –

+0

위대한 !! 고마워요 !! 이것은 오류가 없음을 보여줍니다 !! 나는 안드로이드를 처음 사용하기 때문에 이것은 새로운 것이 었습니다 ... 나는 새로운 활동에서 이미지를 보지 못했습니다 ... 나는 logcat W/ImageView (5381)에서 아래를보고 있습니다 : android.content.res.Resources $ (이미지 뷰, 텍스트 뷰 등)의 리소스 ID입니다. NotFoundException : 리소스가 드로어 블 (색상 또는 경로)이 아닙니다 : TypedValue {t = 0x12/d = 0x0 a = 2 r = 0x7f050034} – dhiku

+0

R.id.list_image는 뷰 . 실제 이미지에 대한 ID를 전달하려면 R.drawable.image와 유사해야합니다. 분명히 "이미지"는 드로어 블 폴더에 놓았을 때 파일 이름을 지정했을 것입니다. – dymmeh

관련 문제