I am trying to convert an existing project with findViewByIds over to ViewBinding. All of the view IDs outside of the ScrollView are available in Android Studio for use with "binding.viewId..." The problem is none of the views with IDs that are within the ScrollView are available for use with "binding.viewID..." So I am not able to access ImageViews that are within two <include layouts that are within a ViewFlipper in the layout. The simple ViewFlipper toggles between an up arrow ImageView and a down arrow ImageView. The ViewFlipper has an <include layout for the up ImageView and a second <include layout for the down ImageView. The ViewFlipper is inside a LinearLayout and the LinearLayout is inside the ScrollView.
//Activity
private ActivityEditBinding binding;
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityEditBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
// activity_edit.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:focusableInTouchMode="true"
tools:context=".AddorUpdateCardActivity">
...
<RelativeLayout
android:id="@+id/secondLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar" >
<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/secondLinearLayout"
... >
<LinearLayout
android:id="@+id/lowerVFRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:paddingEnd="5dp"
android:orientation="horizontal" >
<ViewFlipper
android:id="@+id/expandVF"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="5dp" >
<include layout="@layout/expand_more_act_edit"
android:id="@+id/expandMore" />
<include layout="@layout/expand_less_act_edit"
android:id="@+id/expandLess" />
</ViewFlipper>
</LinearLayout>
</ScrollView>
</RelativeLayout>
// expand_more_act_edit.xml
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/downArrow"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription="sd"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_expand_more" />
<!-- the down arrow -->
I confirmed that the autogenerated ViewBinding classes have been created. Below is where I am trying to attach a ClickListener to the downArrow but I can't access the downArrow reference. What am I missing here?
***Android Studio says "Cannot resolve symbol 'expandMore'***
binding.expandMore.downArrow.setOnClickListener(v -> {
// change the down arrow to the up arrow and show the 1-20 EditText lines.
expandVF.setDisplayedChild(expandVF.indexOfChild(findViewById(R.id.expandLess)));
moreViewStub.setVisibility(View.VISIBLE);
});
Does ViewBinding not work within a ScrollView? What am I missing here?