Anyway to compare int to drawable?ANDROID

前端 未结 2 860
一向
一向 2021-01-15 17:44

Is there anyway to compare s to a? In this code I have int s as the answer and if the drawable == s then I want to display a \"Correct!\" toast mes

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-15 18:34

    try this

    public void MyClick(View view)
        {
         Drawable fDraw = view.getBackground();
         Drawable sDraw = getResources().getDrawable(R.drawable.twt_hover);
    
          if(fDraw.hashCode() == sDraw.hashCode())
          {
           //Not coming
          }
        }
    

    or use following code

    Use getTag() and setTag() for comparison

提交回复
热议问题