I have two xml layouts.
One with a Button.
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.seluhadu.colorpicker.MainActivity">
<Button
android:id="@+id/button"
android:elevation="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="1dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="123dp"/>
</RelativeLayout>
And one with a Relative Layout with just an id.
maintwo.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.seluhadu.colorpicker.MainActivity">
</RelativeLayout>
I have one MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
I want to click in the Button in the main.xml and change the background color of the Maintwo.xml layout.
I tried to call findViewById
but it is in another xml, so it does not work because setContentView is main.xml
How do I call the id of the other xml to my main Activity?
How do make an onClick listener for the Button and get the id of maintwo.xml to change the background?