๐Ÿ”ฅTIL๐Ÿ”ฅ์ŠคํŒŒ๋ฅดํƒ€ | ๋‹ค์ค‘ ์•กํ‹ฐ๋น„ํ‹ฐ ์œ„์˜ NavGraph

hyihyiยท2024๋…„ 2์›” 28์ผ
1

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
54/69
post-thumbnail

Android Navigation Component๋Š” ์ฃผ๋กœ ๋‹จ์ผ ์•กํ‹ฐ๋น„ํ‹ฐ ๋‚ด์—์„œ ํ”„๋ž˜๊ทธ๋จผํŠธ ๊ฐ„์˜ ์ด๋™์„ ๊ด€๋ฆฌํ•˜๋„๋ก ์„ค๊ณ„

๐Ÿ“–๋งŒ์•ฝ 2๊ฐœ์˜ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•˜๋ฉด navigation ํด๋” ๋ฐ‘์— 2๊ฐœ์˜ graph ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค˜์•ผ ํ•œ๋‹ค.

๋‚˜๋Š” RandomActivity ์œ„์— start, random_option, random_theme, random_result ํ™”๋ฉด์„ ๋„์šฐ๊ณ 

MainActivity ์œ„์— place_list ํ™”๋ฉด์ด ๋œจ๊ฒŒ ํ–ˆ๋‹ค.

๐Ÿ“ ์ฝ”๋“œ

<?xml version="1.0" encoding="utf-8"?>
<navigation 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/random_navigation"
    app:startDestination="@id/navigation_start">

    <fragment
        android:id="@+id/navigation_start"
        android:name="com.twoday.todaytrip.ui.StartFragment"
        android:label="fragment_start"
        tools:layout="@layout/fragment_start">
        <action
            android:id="@+id/action_navigation_start_to_navigation_random_option"
            app:destination="@id/navigation_random_option" />
    </fragment>

    <fragment
        android:id="@+id/navigation_random_option"
        android:name="com.twoday.todaytrip.ui.RandomOptionFragment"
        android:label="fragment_random_option"
        tools:layout="@layout/fragment_random_option">
        <action
            android:id="@+id/action_navigation_random_option_to_navigation_random_theme"
            app:destination="@id/navigation_random_theme" />
    </fragment>

    <fragment
        android:id="@+id/navigation_random_theme"
        android:name="com.twoday.todaytrip.ui.RandomThemeFragment"
        android:label="fragment_random_theme"
        tools:layout="@layout/fragment_random_theme">
        <action
            android:id="@+id/action_navigation_random_theme_to_navigation_random_result"
            app:destination="@id/navigation_random_result" />
    </fragment>

    <fragment
        android:id="@+id/navigation_random_result"
        android:name="com.twoday.todaytrip.ui.RandomResultFragment"
        android:label="fragment_random_result"
        tools:layout="@layout/fragment_random_result">
        <action
            android:id="@+id/action_navigation_random_result_to_navigation_place_list"
            app:destination="@id/navigation_place_list" />
    </fragment>

    <fragment
        android:id="@+id/navigation_place_list"
        android:name="com.twoday.todaytrip.ui.PlaceListFragment"
        android:label="fragment_place_list"
        tools:layout="@layout/fragment_place_list">
    </fragment>
    
</navigation>
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/home_navigation"
    app:startDestination="@id/navigation_place_list">

    <fragment
        android:id="@+id/navigation_place_list"
        android:name="com.twoday.todaytrip.ui.PlaceListFragment"
        android:label="fragment_place_list"
        tools:layout="@layout/fragment_place_list">
       </fragment>

    <fragment
        android:id="@+id/navigation_route"
        android:name="com.twoday.todaytrip.ui.StartFragment"
        android:label="fragment_start"
        tools:layout="@layout/fragment_start">
        </fragment>
    
</navigation>
profile
์ž์œ ๋กญ๊ฒŒ ์“ด ๋‚˜์˜ ์ž์œ ๋กœ์šด Development voyageโ›ต

0๊ฐœ์˜ ๋Œ“๊ธ€