2

Need help. It may be weird.

First activity has listview(like lazyadapter) once i click the list it opens a new activity with description, title and image. But iam not able to display the image. Not sure how to send it ...

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);  }

My Second activity

 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);  
dhiku
  • 1,818
  • 2
  • 22
  • 38

1 Answers1

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

You are passing in a resource ID (an integer) to your intent. When you receive that intent, you extract it using getIntExtra which will give you the value of R.id.list_image. Then you may call setImageResource on your ImageView to set the image.

Calling getStringExtra when you passed in an integer will result in a null string.

dymmeh
  • 22,247
  • 5
  • 53
  • 60
  • Great !! Thanks guys !! This shows no errors !! I am new to android so this is something new for me ... I dont see the image in the new activity ... i am seeing the below in the logcat W/ImageView(5381): android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f050034} – dhiku May 03 '12 at 13:55
  • R.id.list_image is likely a resource ID for a View (imageview, textview, etc). To pass an ID for an actual image it would be something like R.drawable.image; obviously the "image" would be whatever you named your file when you placed it in your drawable folder – dymmeh May 03 '12 at 13:58
  • Thanks Dymmeh and Perroloco for all your help!! That Works !! Bingo :) – dhiku May 03 '12 at 14:07