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

Thread: [RESOLVED] how to compare resources in drawable

  1. #16
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    Is that all? What about the other 5 ImageViews? What happens when user clicks on 2 or 3 or 4 or 5 or 6?
    Do they all change to image 2?
    Do all the other ImageViews show image 1 initially?
    Norm

  2. #17

    Re: how to compare resources in drawable

    Do they all change to image 2?
    YES
    Do all the other ImageViews show image 1 initially?
    YES

    its all ?
    no, i want add the limit of 3 imageview changes at the time max
    and now its working partially i can change each imageview individually but if i change the one of the imageview's i can't touch the others

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

    Re: how to compare resources in drawable

    add the limit of 3 imageview changes at the time max
    That sounds like you need a counter to keep track of the changes and stop doing changes when it reaches 3.

    if i change the one of the imageview's i can't touch the others
    Why is that? How do you know the other's can not be touched?
    Have you tried adding some print statements to show where the execution is going and what the values of the variables are?
    The print out will be in the logcat so you can see what the code was doing.

    The code in post#1 shows that there is ONE listener used for all the ImageViews. I don't see how the one listener can keep track of the state of the 6 ImageViews. There needs to be a way to keep track of the state of all 6 ImageViews.
    One way would be separate listeners for each ImageView.
    Another way might be to use the View passed to the listener to determine which ImageView was pressed to determine what state that ImageView is in.
    Last edited by Norm; December 30th, 2018 at 09:23 AM.
    Norm

  4. #19

    Re: how to compare resources in drawable

    Why is that? How do you know the other's can not be touched?
    im testing the app on my mobile with android studio
    Have you tried adding some print statements to show where the execution is going and what the values of the variables are?
    i only use toast for see the action

    One way would be separate listeners for each ImageView.
    i was trying to avoid doing switch/case for 6 imageview because i will repeat a lot of code

  5. #20
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    Add some print statements in the listener so you can see it if was called. Print out the values used to control the swapping of images so you can see what is being done.

    Can you post the current code?
    Norm

  6. #21

    Re: how to compare resources in drawable

    yes


    Code:
     
    
    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 profile = R.drawable.firstimage;
                    int secondprofile = R.drawable.secondimage;
                    if(imageView instanceof ImageView ){
                        if(savedImageRef == profile){
                            ((ImageView) imageView).setImageResource(R.drawable.secondimage);
                            savedImageRef = secondprofile;
                        }else{
                            ((ImageView) imageView).setImageResource(R.drawable.firstimage);
                            savedImageRef = profile;
                        }
                }
                }};        
    
            mypic1.setOnClickListener(listener);
            mypic2.setOnClickListener(listener);
            mypic3.setOnClickListener(listener);
            mypic4.setOnClickListener(listener);
            mypic5.setOnClickListener(listener);
            mypic6.setOnClickListener(listener);
        }
    Last edited by davidaws; December 30th, 2018 at 10:26 AM.

  7. #22
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    Where is the variable: imageView given a value? Does its value relate to where the user pressed?

    Is that listener supposed to do something different depending on what ImageView was pressed? How does it know which was pressed?



    Is this what the code is supposed to do?
    When any ImageView is pressed, the code should change what is viewed in the ImageView referenced in imageView.
    Norm

  8. #23

    Re: how to compare resources in drawable

    i edited the previous post, maybe there is the problem

    When any ImageView is pressed, the code should change what is viewed in the ImageView referenced in imageView.
    exactly

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

    Re: how to compare resources in drawable

    What class is this method in?
    public void onClick(final View imageView) {

    There is still only one listener without a way to save the state of the 6 ImageViews

    I still do NOT understand what you want the code to do.
    There are 6 unique(???) images being shown.
    What is supposed to happen when any one of the images is pressed?
    What is supposed to happen after that when another image is pressed?

    Are there 12 images? 6 are shown initially and 6 that will be shown after a press on one of the images


    Does only the image at imageView get changed? The 6 images shown in the post are not changed.
    Last edited by Norm; December 30th, 2018 at 03:03 PM.
    Norm

  10. #25

    Re: how to compare resources in drawable

    imagine 6 images as x if the user click turns in a circle, if click again its a x again...
    its only a selector activity i don't need process data its only the change of images

    Does only the image at imageView get changed? The 6 images shown in the post are not changed.
    yes if i click in one image, changes to the other i already test on my mobile
    Last edited by davidaws; December 30th, 2018 at 04:57 PM.

  11. #26
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,850

    Re: how to compare resources in drawable

    Are there more than 6 images shown: For example 1 by itself (at imageView) and 6 in a row (at profile1 to profile6)?
    When any one of the 6 images is pressed, the 1 by itself changes, the 6 remain the same.
    Then if one of the 6 images is pressed again, the 1 by itself changes back to its original image. The 6 images stay the same.
    There are only two different images that are shown in the 1 by itself. Pressing any of the 6 will toggle what is shown in the 1 by itself.
    Last edited by Norm; December 30th, 2018 at 05:12 PM.
    Norm

  12. #27

    Re: how to compare resources in drawable


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

    Re: how to compare resources in drawable

    The posted pictures just show 6 red colored rectangles on a blue background.
    Then some of the rectangles are yellow.
    What did the user do between picture one and picture 2?

    Can you explain what should happen when one of the images is pressed?

    Then what happens after another image is pressed?

    Then what happens after another image is pressed?

    The two posted pictures suggest that the color of a rectangle is changed from red to yellow.


    Where is the method onClick called?
    public void onClick(final View imageView) {
    Norm

  14. #29

    Re: how to compare resources in drawable

    What did the user do between picture one and picture 2?
    click on the imageview changed

    Can you explain what should happen when one of the images is pressed?
    change from image 1 to image2

    Then what happens after another image is pressed?
    change the second
    Then what happens after another image is pressed?
    change the 3
    The two posted pictures suggest that the color of a rectangle is changed from red to yellow.
    yes its only a example i need change from @drawable/image.jpg to @drawable/image2.jpg

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

    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?
    There is only one yellow image and that one image is what replaces any of the red images that were clicked on.

    The earlier posts had logic to test what had been shown before and to change it to a different image.
    Is that still true?
    Or is there only one change to be done: from the initial red image to the yellow image?
    Norm

Page 2 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)