2012-05-04 3 views
1

이미지 리소스 (버튼에 사용 된 커버 이미지) 또는 이미지 리소스의 파일 경로를 기준으로 두 ImageView 객체를 비교해야합니다. 나는 두 개의 이미지 뷰 구성 요소를 비교에 대해 갈 수있는 방법을ImageView 오브젝트 비교

final ImageView button01 = (ImageView) findViewById(R.id.button01); 
final ImageView button02 = (ImageView) findViewById(R.id.button02); 
button01.setImageResource(R.drawable.myDogsPhoto); 
button02.setImageResource(R.drawable.myDogsPhoto); 
if (button01.getImageResource() == button02.getImageResource()) { 
return true; 
} 

누군가가 말해 주시겠습니까 :의 라인을 따라

뭔가?

감사

답변

1

하나의 잠재적 인 방법은 자원 값 (또는 파일 경로 문자열)를 저장하기 위해 View.setTag(); 방법을 사용하는 것입니다. setTag() 및 getTag() 메서드를 사용하면 임의의 데이터를 View 객체에 첨부 할 수 있습니다.이 객체는 나중에 필요할 때 호출 할 수 있습니다. 예를 들어

:이 컴파일되지 않은

final ImageView button01 = (ImageView) findViewById(R.id.button01); 
final ImageView button02 = (ImageView) findViewById(R.id.button02); 

button01.setImageResource(R.drawable.myDogsPhoto); 
button01.setTag(R.drawable.myDogsPhoto); 
button02.setImageResource(R.drawable.myDogsPhoto); 
button02.setTag(R.drawable.myDogsPhoto); 
if (button01.getTag().equals(button02.getTag())) { 
    return true; 
} 

주, 그것은 당신의 SetTag에 전달할 정수 객체를 만들 수도 있습니다().

나는 이것이 당신이하고 싶은 일에 대해 최선의 방법인지는 모르겠지만 마음에 처음 나온 사람입니다.

2

는 두 개의 이미지 뷰 개체 ::

button01 =(ImageView)findViewById(R.id.button01); 
button02 =(ImageView)findViewById(R.id.button02); 

Drawable d=button01 .getDrawable(); 
Drawable d1=button02 .getDrawable(); 
if(d== d1){ 
    Toast.makeText(Example.this, "hello", Toast.LENGTH_SHORT).show(); 
}else { 
    Toast.makeText(Example.this, "hai", Toast.LENGTH_SHORT).show(); 
} 
비교