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

Thread: [RESOLVED] how to compare resources in drawable

  1. #46

    Re: how to compare resources in drawable

    yes

    Code:
    https://stackoverflow.com/questions/53909909/how-to-know-which-imageview-is-clicked-and-change-image

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

    Re: how to compare resources in drawable

    As a link https://stackoverflow.com/questions/...d-change-image

    lease answer this question:
    How is this method called:
    Code:
        public void onClick(final View imageView) {
    Last edited by Norm; January 1st, 2019 at 08:32 AM.
    Norm

  3. #48

    Re: how to compare resources in drawable

    on the xml i use this

    Code:
                    
    
    <ImageView
                    android:id="@+id/select2"
                    android:layout_width="100dp"
                    android:layout_height="200dp"
                    android:layout_marginStart="24dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:onClick="onClick"
                    android:src="@drawable/profileold"
                    app:layout_constraintEnd_toStartOf="@+id/select6"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

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

    Re: how to compare resources in drawable

    It is confusing to use the same method name as used by the OnClickListener.

    Is that another ImageView? It is not one of the 6 that are used in the rest of the code?
    Are There a total of 7 ImageViews: this one and the other 6?

    Are there two click listeners for each ImageView? One in the xml and one in the code?

    I see that select2 has 2.
    Last edited by Norm; January 1st, 2019 at 09:39 AM.
    Norm

  5. #50

    Re: how to compare resources in drawable

    yes sr norman i fix these problem and i delete a lot of garbage now my code is more simple

    Code:
    int savedImageRef = R.drawable.image2;
        public void onClick(final View imageView) {
            int profileold = R.drawable.image1;
                    int profilenew = R.drawable.image2;
                    if(imageView instanceof ImageView ){
                        if(savedImageRef == seleccion){
                            ((ImageView) imageView).setImageResource(R.drawable.profileold);
                            savedImageRef = profileold;
                        }else{
                            ((ImageView) imageView).setImageResource(R.drawable.profilenew);
                            savedImageRef = profilenew;
                        }
            }
        }
    and now i can change the image 1 to image 2 and select others imageview successfully the only detail now is

    i have to click 2 times for the first change

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

    Re: how to compare resources in drawable

    i have to click 2 times for the first change
    What does the code do on the first click?
    Try doing some debugging by adding some print statements that show what the code is doing, where it is executing and what the values of variables are when they are used.
    The output from the print statement will show in the logcat.
    Norm

  7. #52

    Re: how to compare resources in drawable

    What does the code do on the first click?
    the idea is change the image from image 1 to image2 but i see the logcat message, so the click is readed by the mobile but don't changed

    Try doing some debugging by adding some print statements that show what the code is doing, where it is executing and what the values of variables are when they are used.
    i add 1 tag for the launch of the activity 1 log for the first click and1 for the second and i see all the messages but on the first click the image doesn't change

    The output from the print statement will show in the logcat.

    maybe the problem is here, when the actiivty opens i see this message only i time

    D/OpenGLRenderer: endAllStagingAnimators on 0xb4bc0700 (RippleDrawable) with handle 0xaf82cec0
    Last edited by davidaws; January 1st, 2019 at 03:29 PM.

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

    Re: how to compare resources in drawable

    output from the print statement will show in the logcat.
    Please copy the content from the logcat that shows what your code printed.
    Also post the code with the print statements so the print out can be evaluated.

    the click is readed by the mobile but don't changed
    What methods were executed? What were the values of the variables when the code was executed?

    Here is an example of debugging print statements:
    Code:
        public void onClick(final View imageView) {
            System.out.println("onClick iV="+imageView); //<<<<<<
            int profileold = R.drawable.image1;
                    int profilenew = R.drawable.image2;
                    if(imageView instanceof ImageView ){
                        System.out.println("sIF="+savedImageRef + ", seleccion="+seleccion); //<<<
                        if(savedImageRef == seleccion){
                            System.out.println("changed to " + R.drawable.profileold + " " +profileold);   //<<<<<<
                            ((ImageView) imageView).setImageResource(R.drawable.profileold);
                            savedImageRef = profileold;
                        }else{
                            ((ImageView) imageView).setImageResource(R.drawable.profilenew);
                            savedImageRef = profilenew;
                            System.out.println("changed to " + R.drawable.profilenew + " " +profilenew);  //<<<<<
                       }
            }
        }
    Last edited by Norm; January 1st, 2019 at 03:28 PM.
    Norm

  9. #54

    Re: how to compare resources in drawable

    thanks, this is the result

    1) click
    I/System.out: onClick iV=android.support.v7.widget.AppCompatImageView{3d03cfad V.ED..C. ...P.... -2,16-198,416 #7f0800a1 app:id/selectcarta2}
    sIF=2131165277, profilenew=2131165278
    changed to 2131165277 2131165277
    2) click
    I/System.out: onClick iV=android.support.v7.widget.AppCompatImageView{3d03cfad V.ED..C. ...P.... -2,16-198,416 #7f0800a1 app:id/selectcarta2}
    sIF=2131165278, profilenew=2131165278
    I/System.out: changed to 2131165278 2131165278

    i understand this, the image is changed for the same, so the logic is wrong im replacing the image 1 by image 1.

    i will do some test now


    YES SR That was the problem, thanks a lot norm i learn a lot with your help
    Last edited by davidaws; January 1st, 2019 at 03:49 PM.

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

    Re: how to compare resources in drawable

    What was showing before the first click?

    What did you observe to happen after the first click?

    What happened after the second click?

    For the first click:
    sIF=2131165277, seleccion=2131165278
    The values are not equal so the if test is false.
    changed to 2131165277 2131165277
    The ImageView's image is changed to what was in savedImageRef.
    Where did savedImageRef get assigned that value before the first click?



    sIF=2131165278, seleccion=2131165278
    For the second click, the values are the same so the if test is true.

    Where is seleccion defined? Where is it assigned values?
    Last edited by Norm; January 1st, 2019 at 04:21 PM.
    Norm

  11. #56

    Re: how to compare resources in drawable

    yes, was a problem of assignments, i already fix that and now works with the first click ^^

    YES SR That was the problem, thanks a lot norm i learn a lot with your help

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

    Re: how to compare resources in drawable

    I'm glad you figured it out.
    Have a happy new year.
    Norm

  13. #58

    Re: [RESOLVED] how to compare resources in drawable

    thanks for the patience and Have a happy new year you too.

Page 4 of 4 FirstFirst 1234

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)