id の代わりに tag を使う
<1>
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int idLayoutActivityMain = getApplication().getResources().getIdentifier("activity_main", "layout", getApplication().getPackageName());
rootView = inflater.inflate(idLayoutActivityMain, null);
setContentView(rootView);
ImageView imageView = rootView.findViewWithTag("imageView" );
<2>Layout XMLにはidの代わりにtagを追加
【activity_main.xml】
<ImageView
android:id="@+id/imageView"
android:tag="imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
コメントを残す