• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps simple assistance in making activity

Hayabusa

Lurker
May 2, 2015
2
0
Witam mam na imię Mateusz.
Od niedawna zacząłem programować w Android Studio, jestem początkujący wieć nawet najprostsze działania są dla mnie trudne. A więc chciałbym się dowiedzieć jak mogę się poruszać między layout mam naprzykład activity_main.xml w którym jest button o nazwie CHANGE i po kliknięciu chciałbym aby otworzyl mi sie drugi layout o nazwie second.xml and that's all I would like to receive the rest I can handle it :)

**mod translate**
Hello my name is Matthew.
Recently, I started to program in Android Studio, I'm a beginner so even the simplest actions are difficult for me. And so I would like to know how I can move between a layout I activity_main.xml instance in which it is called CHANGE button and click I would like to opened a second layout named second.xml and that's all I would like to receive the rest I can handle it :)

77459815615026097552.png
 
Last edited by a moderator:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello world!"/>
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change"
android:layout_centerInParent="true"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/secondLayout"
android:visibility="gone"
android:background="#ffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Second Layout"
android:textSize="24sp"
/>
</RelativeLayout>
</RelativeLayout>
Then in Activity code
Java:
findViewById(R.id.myButton).setOnClickListener(new OnClickListener()
{
        findViewById(R.id.secondLayout).setVisibility(View.VISIBLE);
}
);
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones