I'm starting a new Activity via intent from a ListViewItem. However, new detail Activity displays the info of the ListViewItem in the -1 position.
I instantiate and start the Activity here:
ListView list = (ListView)findViewById(R.id.merchListView);
list.setAdapter(merchItemArrayAdapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplication(),String.format("view==>%s, position ==> %s, id==> %s",view.toString(),position,id),Toast.LENGTH_SHORT).show();
System.out.println(String.format("view==>%s, position ==> %s, id==> %s",view.toString(),position,id));
//Build Intent
Intent intent = new Intent(getApplicationContext(),MerchItemDescription.class);
TextView tv1 = (TextView) findViewById(R.id.textView2);
TextView tv2 = (TextView) findViewById(R.id.costView);
ImageView iv1 = (ImageView) findViewById(R.id.imageView);
System.out.println(String.format("Imageview id is ==> %d",R.id.imageView));
iv1.buildDrawingCache();
Bitmap imageViewImage = iv1.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", imageViewImage);
//extras.putParcelable("theView", view);
intent.putExtras(extras);
String message = tv1.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
String costViewString = tv2.getText().toString();
intent.putExtra(ITEM_COST,costViewString);
startActivity(intent);
}
});
Here is the class passed to the Intent:
setContentView(R.layout.merch_item_description);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivityTest.EXTRA_MESSAGE);
System.out.println(String.format("Message ==> %s", message));
//View merchDescView = getLayoutInflater().inflate(R.layout.merch_item_description, null, false);
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
//View myView = (View) extras.getParcelable("theView");
TextView txtView2 = (TextView)findViewById(R.id.textViewLongDesc);
//TextView txtView2 = (TextView) myView.findViewById(R.id.textViewLongDesc);
txtView2.setText(message);
ImageView iv = (ImageView)findViewById(R.id.itemDescIV);
//ImageView iv = (ImageView) myView.findViewById(R.id.itemDescIV);
iv.setImageBitmap(bmp);
If tv1, tv2 and iv1 are children of items in the ListView, instead of:
TextView tv1 = (TextView) findViewById(R.id.textView2);
TextView tv2 = (TextView) findViewById(R.id.costView);
ImageView iv1 = (ImageView) findViewById(R.id.imageView);
You might mean:
TextView tv1 = (TextView) view.findViewById(R.id.textView2);
TextView tv2 = (TextView) view.findViewById(R.id.costView);
ImageView iv1 = (ImageView) view.findViewById(R.id.imageView);
It may be finding the first R.id.* in the Activity rather than the child view.