Muhammad Umar Muhammad Umar - 6 months ago 21
Android Question

starting activity on imageview click in custom array adapter

I have made a custom adapter class

here is the code

public class CustomArrayAdapterForReceipts extends ArrayAdapter<Receipt> {
private final Activity context;
public final ArrayList<Receipt> receipt;

public CustomArrayAdapterForReceipts(Activity context, ArrayList<Receipt> receipt) {
super(context, R.layout.row_layout_receipts_listview, receipt);
this.context = context;
this.receipt = receipt;
}

static class ViewHolder {
protected TextView referenceNo;
protected TextView comments;
protected ImageView receiptImage;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view = null;
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.row_layout_receipts_listview, null);
final ViewHolder viewHolder = new ViewHolder();

viewHolder.referenceNo = (TextView) view.findViewById(R.id.rowReceiptTitle);
viewHolder.comments = (TextView) view.findViewById(R.id.rowReceiptComments);
viewHolder.receiptImage = (ImageView) view.findViewById(R.id.rowReceiptImage);

Receipt file = receipt.get(position);
final byte[] blob = file.getImage();
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap imageBitmap = BitmapFactory.decodeStream(inputStream);
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 30, 30, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
viewHolder.receiptImage.setImageBitmap(imageBitmap);

viewHolder.receiptImage.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(v.getContext(), TransferController.class);
myIntent.putExtra("image", blob);
startActivity(myIntent);
}
});

viewHolder.referenceNo.setText(file.getReferenceNo());
viewHolder.comments.setText(file.getComments());


view.setTag(viewHolder);

return view;
}
}


The problem exists at

myIntent.putExtra("image", blob);
startActivity(myIntent);


startActivity
is not being recognized... Please tell me, i want to start a new activity here. What should i do...

BEST Regards

Answer

try like this you can get

v.getContext().startActivity(myIntent);