How to reference an object from one Activity to the other?

Asked

Viewed 119 times

0

Good evening, I am developing an application containing several buttons, in which you can drag a button and drop in a certain place already defined in the application, and each button has to open another screen with an animated image (GIF) different, but that has to do with the dragged button, how to set the image for each button? And what to call it? It follows below the piece of code I’m having difficulty.

View.Onlongclicklistener longClickListener = new View.Onlongclicklistener() {

    public boolean onLongClick(View v) {
        ClipData data = ClipData.newPlainText("","");
        View.DragShadowBuilder myShadowBuilder = new View.DragShadowBuilder(v);
        v.startDrag(data, myShadowBuilder, v, 0);
        return true;
    }
};
    View.OnDragListener dragListener = new View.OnDragListener() {
        @Override
        public boolean onDrag(View v, DragEvent event) {

            int dragEvent = event.getAction();

            switch (dragEvent){
                case DragEvent.ACTION_DRAG_ENTERED:
                    break;

                case DragEvent.ACTION_DRAG_EXITED:
                    break;

                case DragEvent.ACTION_DROP:
                    final View view = (View) event.getLocalState();

                    if(view.getId() == R.id.btA){
                        Intent TelaBoca = new Intent(TelaAprendizagem.this, TelaFala.class);
                        startActivity(TelaBoca);
                    }
                    break;
            }
            return true;
        }
    };

1 answer

0

What you can do is, in this code snippet

if(view.getId() == R.id.btA){
    Intent TelaBoca = new Intent(TelaAprendizagem.this, TelaFala.class);

    //Trecho incluido-------------------------------------------------
    TelaBoca.putExtra("viewId", view.getId());
    //----------------------------------------------------------------

    startActivity(TelaBoca);
}

send the id of the view as an Extra in the Intent, through the putExtra() of the Intent.

Then in the other Activity, you would take the Intent of it and check if you have an Id listed, and show the corresponding image.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.