Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:46:26+00:00 2026-06-17T13:46:26+00:00

i am trying to compare the view background to the drawable but its not

  • 0

i am trying to compare the view background to the drawable but its not working for me.

View v1 = options.findViewById(i);
v1.findViewById(R.drawable.back);
Drawable d = v1.getBackground();       

if(d.getConstantState() == getResources().getDrawable(R.drawable.correct_ans_back)){
    v1.setBackgroundResource(R.drawable.a);             
}else{
    view.setBackgroundResource(R.drawable.b);               
}

how to check i am getting an error here.

incompatible operand types Drawable.Constant State and Drawable
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:46:27+00:00Added an answer on June 17, 2026 at 1:46 pm

    1) Replace

    if(d.getConstantState() == getResources().getDrawable(R.drawable.correct_ans_back))
    

    with

    if(d.getConstantState() == getResources().getDrawable(R.drawable.correct_ans_back).getConstantState())
    

    This will solve the incompatible operand types Drawable.Constant State and Drawable error.

    2) If you are not able to compare two bitmaps, then you can use the below method.

    public boolean compareDrawable(Drawable d1, Drawable d2){
        try{
            Bitmap bitmap1 = ((BitmapDrawable)d1).getBitmap();
            ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
            bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, stream1);
            stream1.flush();
            byte[] bitmapdata1 = stream1.toByteArray();
            stream1.close();
    
            Bitmap bitmap2 = ((BitmapDrawable)d2).getBitmap();
            ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
            bitmap2.compress(Bitmap.CompressFormat.JPEG, 100, stream2);
            stream2.flush();
            byte[] bitmapdata2 = stream2.toByteArray();
            stream2.close();
    
            return bitmapdata1.equals(bitmapdata2);
        }
        catch (Exception e) {
            // TODO: handle exception
        }
        return false;
    }
    

    3) OR , you can assign two different TAG to the background images and compare the TAG only instead of comparing drawable directly.
    You can also set background’s TAG as drawable’s id and compare it as described below,

    Object tag = bgView.getTag(); 
    int backgroundId = R.drawable.bg_image;
    if( tag != null && ((Integer)tag).intValue() == backgroundId) {
       //do your work.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to compare these two chars but on win 32 Visual Studio 2008:
I'm trying to compare the differences between jQuery and JavaScript in a project, but
I'm trying to compare two different column types (not my doing, part of a
Background: The application I am working on happens to be web-based, but the question
I'm trying to compare two cars details in the same View page. I do
I am trying to compare a view tag with another tag by using the
I'm trying to include the unobtrusive.js to my mvc3 view, but when I do,
I am trying to navigate into the Price model to compare prices, but met
I'm trying to pass a ViewModel property to a partial view, but getting the
Trying to compare and print only members with Inactive status. The problem is that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.