Search code examples
androidclickable

Disable click if background color is of a particular type


I am trying to achieve as mentioned in the title. If the backgroundcolor of my layout is say #F0F0F0 then the click should be disabled. Something like this:

final RelativeLayout row = (RelativeLayout) fragmentView.findViewById(R.id.row);

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long mallId) {

            //disable click if background color is #F0F0F0
            if(row.getBackground() is #F0F0F0){
              //do nothing
            }
            else {
            Intent intent = new Intent(getActivity(), ShopActivity.class);
            intent.putExtra("MALL_ID", (int) mallId);
            startActivity(intent);
            }
        }
    });

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/row"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F0F0F0"
    android:paddingBottom="7dp">
    ...
</RelativeLayout>

Solution

  • if( ((ColorDrawable)row.getBackground()).getColor() == Color.parseColor("#F0F0F0")){
        //do nothing
    }
    else{
        //...
    }