dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 58

Thread: [RESOLVED] how to compare resources in drawable

  1. #31

    Re: how to compare resources in drawable

    Ok, so each click on one of the 6 red images will change what is shown to be the yellow image?
    yes and if click on the red it turns to the first image again

  2. #32
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    it turns to the first image again
    Ok does that mean the code must remember what was shown before so it can restore it?
    And it must know what ImageView was pressed.

    Are there 7 unique images, 6 are shown initially, the 7th image is not shown?
    If a user clicks on image 2 of the 6 images, it is replaced by the 7th image.
    Next if image 5 is clicked on, it is replaced by the 7th image. Now the 7th image is shown in two places: 2 and 5.
    If the user clicks on image 2 then the 7th image is replaced with what was originally in location 2. Now the 7th image is only shown in location 5.
    Last edited by Norm; December 31st, 2018 at 09:40 AM.
    Norm

  3. #33

    Re: how to compare resources in drawable

    men, its really simple a imageview with 2 states, image 1 and image 2 i can't expain the same again and again...

  4. #34
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    imageview with 2 states, image 1 and image 2
    That makes it a little clearer.
    Is this what you are trying to do?
    There are a total of 12 images, with 6 being shown initially and 6 not shown.
    Each image being shown has a unique image paired with it that should replace it when it is clicked on.
    In other words for each of the 6 ImageView slots there are two images: the initial image and the replacement image.
    The images for a ImageView slot swap from one to the other and back as they are clicked.
    Norm

  5. #35

    Re: how to compare resources in drawable

    There are a total of 12 images, with 6 being shown initially and 6 not shown.
    no, i have 6 imageviews with only 2 drawable resources image1, and image2

    The images for a ImageView slot swap from one to the other and back as they are clicked.
    exactly that no more complications you already say what i need

  6. #36
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    i have 6 imageviews with only 2 drawable resources image1, and image2
    Ok, that's a little more info about the project.
    Then each ImageView needs a place to save its state - whether it is showing image 1 or image 2

    One way would be a Map<ImageView, IVState> where IVState is a class that holds what image is being shown in the associated ImageView. The onClick method is passed a reference to the ImageView that would be used as the key to get the IVState object with the information about that ImageVIew.
    Norm

  7. #37
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,940

    Re: how to compare resources in drawable

    @OP. In my opinion you are trying to solve too much of the problem all at once. I would separate the click logic from the image code. To this end I would create a small test app that displays different color squares and write the ui logic to change color according to the desired behavior when you click on a square. Once you get that working, I would pull that code back into the original program and replace the change color part so it changes images.

  8. #38

    Re: how to compare resources in drawable

    ok, thanks but already the app it's working partially i can choose 1 image and it change to the desired image but i can't choose other

  9. #39
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    Post the current code so we can see what it does.

    The code needs to know which ImageView was pressed and what the current state of the ImageView is.
    There needs to be a place to save that state. A Map is one way to save the state.
    Another way is to define a listener class that holds the state and create an instance of it for each ImageView.
    Norm

  10. #40
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,940

    Re: how to compare resources in drawable

    Quote Originally Posted by davidaws View Post
    ok, thanks but already the app it's working partially i can choose 1 image and it change to the desired image but i can't choose other
    Yes, the exact reason I suggested creating a test app where you could sort out the click and state logic

  11. #41

    Re: how to compare resources in drawable

    this is the last code:




    Code:
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    
    public class SelectActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.select_images);
            Button btn;
            btn = findViewById(R.id.button_resultados);
            btn.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(v.getContext(), ResultadosActivity.class);
                    startActivityForResult(intent, 0);
                }
            });
        }
        int savedImageRef = R.drawable.image1;
    
        public void onClick(final View imageView) {
            ImageView mypic1 = (ImageView) findViewById(R.id.select1);
            ImageView mypic2 = (ImageView) findViewById(R.id.select2);
            ImageView mypic3 = (ImageView) findViewById(R.id.select3);
            ImageView mypic4 = (ImageView) findViewById(R.id.select4);
            ImageView mypic5 = (ImageView) findViewById(R.id.select5);
            ImageView mypic6 = (ImageView) findViewById(R.id.select6);
    
            View.OnClickListener listener= new OnClickListener() {
                public void onClick(View v) {
                    int profileold = R.drawable.image1;
                    int profilenew = R.drawable.image2;
                    if(imageView instanceof ImageView ){
                        if(savedImageRef == profilenew){
                            ((ImageView) imageView).setImageResource(R.drawable.profileold);
                            savedImageRef = profileold;
                        }else{
                            ((ImageView) imageView).setImageResource(R.drawable.profilenew);
                            savedImageRef = profilenew;
                        }
                }
                }};
            mypic1.setOnClickListener(listener);
            mypic2.setOnClickListener(listener);
            mypic3.setOnClickListener(listener);
            mypic4.setOnClickListener(listener);
            mypic5.setOnClickListener(listener);
            mypic6.setOnClickListener(listener);
        }
    
        }
    Last edited by davidaws; January 1st, 2019 at 07:22 AM.

  12. #42
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,940

    Re: how to compare resources in drawable

    As Norm mentioned
    The code needs to know which ImageView was pressed and what the current state of the ImageView is.
    There needs to be a place to save that state. A Map is one way to save the state.
    Doesn't look like your code is tracking the state for each ImageView.

  13. #43
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    How is this method called:
    Code:
        public void onClick(final View imageView) {
    It is confusing because that is the method name for the ClickListener method. If it is part of a listener where is it set?
    If it is not in a listener it should have a different name to prevent confusion


    Where is the variable: seleccion defined and given a value?
    Last edited by Norm; January 1st, 2019 at 06:34 AM.
    Norm

  14. #44

    Re: how to compare resources in drawable

    Where is the variable: seleccion defined and given a value?
    hi, i edit the code again fixing the the value

    and how i can track the imageview clicked? because i use these code because i programmer on stackoveflow tellme

    i can't track the imageview clicked here?
    if(imageView instanceof ImageView ){
    i don't know how to proceed

  15. #45
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    how i can track the imageview clicked
    The View is passed to the onClick method.

    Please answer this question:
    How is this method called:
    Code:
        public void onClick(final View imageView) {
    Please post a link to this:
    programmer on stackoveflow tellme
    Last edited by Norm; January 1st, 2019 at 07:34 AM.
    Norm

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)