I have list of product. When the user click on the row, the Toast
msg will be displayed the name of the product.
I want to display the Toast
on the each product row line.I want to show the Toast in the place where user click on list' row
See my picture;
Currently displaying center of List:
I did like this :
tablerow.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast prName = Toast.makeText(RetailerOrderActivity.this,
" Name : " + productList.get(Integer.parseInt(view.getTag().toString())).getDescription(),
Toast.LENGTH_SHORT);
prName.setGravity(Gravity.AXIS_SPECIFIED, 0, 0);
prName.show();
}
});
Try this,
int[] values= new int[2];
view.getLocationOnScreen(values);
int x = values[0];
int y = values[1] ;
toast.setGravity(Gravity.TOP|Gravity.LEFT, x, y);
The 2nd and 3rd params of setGravity()
are x and y offsets from the constant specified in the 1st param. You will need to get the x&y position of the row view object you wish to position the toast above. Or you could get the x&y of the touch event.
Personally I would start with setGravity(Gravity.TOP|Gravity.LEFT,0,0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With