I have a listview which displays items retrieved from the database. Each item in the listview has a share button which allows the user to share the information. However when I click on the share button, the information displayed is different from the item I clicked. And the no matter which item I click, it will be getting information of the first few item.
For example, clicking on item N 2 would display info of item N 3. In other words, no matter which item I click, it will be displaying wrong information. Am I doing anything wrong here?
**The listview displays items correctly flawlessly.
Adapter.java
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
if(convertView==null){
v = vi.inflate(Resource, null);
holder = new ViewHolder();
holder.titre = (TextView) v.findViewById(R.id.titre);
holder.artist = (TextView) v.findViewById(R.id.artist);
holder.imageview = (ImageView) v.findViewById(R.id.urlImage);
v.setTag(holder);
}
else
holder=(ViewHolder)v.getTag();
holder.titre.setText(mediaList.get(position).getTitre());
holder.artist.setText(mediaList.get(position).getArtist());
imageLoader.DisplayImage(mediaList.get(position).getUrl(), loader, holder.imageview );
Button button = (Button) v.findViewById(R.id.btnOne);
//holder=(ViewHolder)v.getTag();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick( View v) {
//holder=(ViewHolder)v.getTag();
//v.setTag(holder);
//onShareItem( v);
v.getTag();
Drawable mDrawable = holder.imageview.getDrawable();
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.PNG, 1, bytes);
String path = Images.Media.insertImage(context.getContentResolver(),
mBitmap, "Image Description", null);
Uri imageUri = Uri.parse(path);
sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sharingIntent.setType("image/*");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity( sharingIntent);
}
});
v.setTag(holder);
return v;
}