vendredi 20 avril 2018

Sending images from one class to another class (activity to activity)

I've attached my code below.

It's pretty rough at the minute, I've struggled to get it working.

Basically the user selects an image from a page, then it will load into another (the workout hub).

Here is where I am sending the information (image) I basically want the user to be able to select an image and dynamically add on an image view into the second activity (this is from the first activity)

 /**
     *
     */
    protected void loadPullUps(){

        Intent loadPullUpImage= new Intent(this, workout_loader.class);
        //loadPullUpImage.putExtra("pull-ups", byteArray);
        loadPullUpImage.putExtra("pull_ups_var", true);
        startActivity(loadPullUpImage);

    }

    /**
     *
     */
    protected void loadReverseRows(){

        Intent loadReverseRowImage= new Intent(this, workout_loader.class);
        //loadPullUpImage.putExtra("pull-ups", byteArray);
        loadReverseRowImage.putExtra("reverse_rows_var", true);
        startActivity(loadReverseRowImage);

    }

    /**
     *
     */
    protected void loadRackPulls(){


    }

This is my second activity where I will load the image into, where I expect the users selections to appear. The first one loadPullups() works, yet from there it crashes if I select another and the code is generally bad. I've spent around 14 hours today trying to get it work and I'm facing a wall.

     protected void loadWorkout(){

     /*   int[] myImageList = new int[]{R.drawable.pull_ups, R.drawable.rack_pulls, R.drawable.reverse_rows,
                R.drawable.cable_curls, R.drawable.ez_bar_curls, R.drawable.bicep_curls_exercise, R.drawable.chest_press,
                R.drawable.cable_crossovers, R.drawable.push_ups, R.drawable.tricep_pulldowns, R.drawable.tricep_kickbacks,
                R.drawable.tricep_dips, R.drawable.dumbbell_press, R.drawable.shoulder_shrugs, R.drawable.shoulder_flyes,
                R.drawable.barbell_squat, R.drawable.leg_extensions, R.drawable.leg_press};

*/
        Bundle extras = getIntent().getExtras();



        LinearLayout layout = (LinearLayout)findViewById(R.id.container);
       /*for(int i=0;i<10;i++)
        {
            ImageView image = new ImageView(this);
            image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80,60));
            image.setMaxHeight(500);
            image.setMaxWidth(200);

            // Adds the view to the layout
            image.setImageResource(R.drawable.pull_ups);

            layout.addView(image);
        }
*/



            if (extras.getBoolean("pull_ups_var")) {
                Log.e("AFTER\t", " " + extras.getBoolean("pull_ups_var"));
                int[] images = {R.drawable.pull_ups};
                int cImage = images[0];
                imgView1.setImageResource(cImage);
            }
            else if (extras.getBoolean("reverse_rows_var")) {
                Log.e("AFTER\t", " " + extras.getBoolean("reverse_rows_var"));
                int[] images = {R.drawable.reverse_rows};
                int cImage = images[2];
                imgView2.setImageResource(cImage);
            }
        }


    }

Aucun commentaire:

Enregistrer un commentaire