How to save the id of a relativeLayout?

0

Hello, good afternoon. I'm new to Android programming and I'm not able to save the ID of a relativeLayout to be compared.

Example:

 <RelativeLayout
        android:id="@+id/idAmc"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:layout_marginBottom="15dp"
        android:background="@drawable/shadow_grey"
        android:clickable="true"
        android:onClick="selecionaMenuTec">

        <ImageView
            android:id="@+id/ic_amc"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="15dp"
            app:srcCompat="@drawable/ic_amc" />

        <TextView
            android:id="@+id/amc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/amc"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/empresaAmc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginStart="12dp"
            android:layout_toEndOf="@+id/ic_amc"
            android:text="ABC Empresa"
            android:textAppearance="@style/TextAppearance.AppCompat.Body2"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/mediaAmc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/empresaAmc"
            android:layout_marginLeft="180dp"
            android:text="@string/media" />

        <TextView
            android:id="@+id/mediaValorAmc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:text="0%"
            android:textSize="25sp"
            android:layout_alignParentBottom="true"
            android:layout_toEndOf="@+id/mediaAmc" />


    </RelativeLayout>

How do I get the ID of this relativeLayout and save it to a variable for future comparison?

I've tried using findViewById () but not sure.

I want to do something like: '

public class menuTec extends AppCompatActivity{

public void selecionaMenuTec(RelativeLayout view)
{
    RelativeLayout layoutMenuTec = view;



    if( view == R.id.idAmc){



    }

}

}

    
asked by anonymous 23.05.2017 / 16:01

1 answer

0

Your code is not working because you are comparing a View with an integer .

The correct thing is to get the view from view that the method receives as a parameter, like this:

public void selecionaMenuTec(View view){
    if (view.getId() == R.id.idAmc) {
        // faça alguma coisa
    }  
}
    
23.05.2017 / 16:15