2

I want to log the ID of a particular child View inside RelativeLayout. I used the below code to get that. But the ID is logged twice.

Code:

ViewGroup parentView = (ViewGroup) v.findViewById(R.id.category_layout);
View childView;
for(int i = 0; i < parentView.getChildCount(); i++) {

    childView = parentView.getChildAt(i);
    int resID = childView.getId();
    if(childView instanceof ViewPager ){
        Log.e("Id",Integer.toString(resID));
    }
}

xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:id="@+id/category_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:id="@+id/pager"
    ></android.support.v4.view.ViewPager>
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycler"
        android:layout_below="@+id/pager">
    </android.support.v7.widget.RecyclerView>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

Log:

E/Id: 2131492989
E/Id: 2131492989
earthw0rmjim
  • 19,027
  • 9
  • 49
  • 63
jobin
  • 1,489
  • 5
  • 27
  • 52

0 Answers0