0

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?

Tomas F.
  • 318
  • 3
  • 14
  • Does this answer your question? [How to change position of Toast in Android?](https://stackoverflow.com/questions/2506876/how-to-change-position-of-toast-in-android) – Nirel Sep 06 '22 at 19:53
  • Do not use a `Toast`. Add your own view to the layout, positioned appropriately, and hide/show that view as needed. – CommonsWare Sep 06 '22 at 21:07
  • 1
    FYI You can't change the toast position anymore. SetGravity() does nothing – javdromero Sep 06 '22 at 21:26

0 Answers0