I have an app with several imageviews in the main activity. When I click on an image a Toast exlaining the image is shown. Default postion is at the bottom of the screen. I know about the: toast.setGravity(int, int, int); But how do I get the position of the view that was clicked? So I can present the toast just above the view?
public class ShowLocationInfo extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_location_info);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (gNewMarinas[gChosenMarinaNr].isMarina)
TAGstrings = getResources().getStringArray(R.array.feature_and_types_explanation_for_marinas);
else
TAGstrings = getResources().getStringArray(R.array.feature_and_types_explanation_for_anchoring);
androidx.appcompat.widget.AppCompatImageView RON95ImageView = findViewById(R.id.ron95_imageview);
RON95ImageView.setOnClickListener(v -> showExplanation(v, ShowLocationInfo.this));
if ((gNewMarinas[gChosenMarinaNr].typesAndFeatures & kRON95Bit) != 0) {
RON95ImageView.setTag(TAGstrings[17]);
RON95ImageView.setVisibility(View.VISIBLE);
} else {
RON95ImageView.setTag(TAGstrings[18]);
RON95ImageView.setVisibility(View.VISIBLE);
RON95ImageView.setImageResource(R.drawable.pump_95_grey);
}
}
void showExplanation(View v, Context context){
if (v.getTag() != null) {
Toast.makeText(context, v.getTag().toString(), Toast.LENGTH_SHORT).show();
}
}
}
Any java guru who knows this?