๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์‹œ๋„/Smart_Fan

[Smart_Fan] 08 - Android Studio : Fragment์•ˆ์— ListView ๊ตฌํ˜„ํ•˜๊ธฐ 02

by ๐Ÿ‡๋ฐ•๋ด‰๋ด‰๐Ÿ‡ 2020. 9. 6.

 

Fragment์•ˆ์— ListView ๊ตฌํ˜„ํ•˜๊ธฐ 02

[2020-07-15]

 

์ €๋ฒˆ์—๋Š” Fragment์•ˆ์— ListView๊ฐ€ ๋ณด์ผ ์ˆ˜ ์žˆ๋„๋ก ์ž…๋ ฅํ•ด ๋ณด์•˜๋‹ค.

 

์ด๋ฒˆ์—๋Š” ListView์— ์žˆ๋Š” ํ•ญ๋ชฉ๋“ค์„ ํด๋ฆญํ•˜๋ฉด

๋‹ค์Œ ํ™”๋ฉด์œผ๋กœ ๋„˜์–ด๊ฐˆ ์ˆ˜ ์žˆ๊ฒŒ intent๋ฅผ ์‚ฌ์šฉํ•ด ๋ณด๋ ค๊ณ  ํ•œ๋‹ค.

 

 

#02. intnet๋ฅผ ์‚ฌ์šฉํ•ด ListView ํ•ญ๋ชฉ ํด๋ฆญ ์‹œ ํ™”๋ฉด ์ „ํ™˜

 

intent

์–ดํ”Œ๋ฆฌ ์ผ€์ด์…˜์„ ๊ตฌ์„ฑํ•˜๋Š” ๋„ค ๊ฐ€์ง€ ๊ธฐ๋ณธ ์š”์†Œ์—๋Š”

Activity, Service, Broadcast Receiver, Content Provider๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š”๋ฐ

์ด๋Ÿฌํ•œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์„ฑ ์š”์†Œ ๊ฐ„์— ์•ก์…˜, ๋ฐ์ดํ„ฐ ๋“ฑ์„ ์ „๋‹ฌํ•˜๋Š” ๋ฉ”์‹œ์ง€ ๊ฐ์ฒด์ด๋‹ค.

 

intent๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ ์˜ˆ์‹œ๊ฐ€ ๋ฐ”๋กœ 

์•กํ‹ฐ๋น„ํ‹ฐ ๊ฐ„์˜ ํ™”๋ฉด ์ „ํ™˜์ด๋‹ค.

 

 

  • settings_advice.xml, settings_temperature.xml, settings_voice.xml, settings_widget.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".Settings_Advice"> <!— ๊ฐ ์ง€์ • ํŒŒ์ผ์— ๋งž๊ฒŒ ํˆด ์ž…๋ ฅ —>

    <LinearLayout
        android:id="@+id/layoutToolBar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="@color/colorPrimary"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingStart="15dp"
        android:paddingEnd="15dp"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Help"
            android:textColor="@color/colorWhite"
            android:textSize="18sp"
            android:textStyle="bold" />

    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/layoutToolBar"
        app:layout_constraintBottom_toBottomOf="parent"
        android:gravity="center"
        android:text="๋„์›€๋ง"
        android:textSize="25sp"
        android:textStyle="bold"/>

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

  • Settings_Advice.java, Settings_Temperature.java, Settings_Voice.java, Settings_Widget.java
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class Settings_Advice extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
	//๊ฐ ํŒŒ์ผ์— ๋งž๊ฒŒ ContentView ์„ค์ •
        setContentView(R.layout.settings__advice);
    }
}

 

์ผ๋‹จ ๊ฐ ๋ฆฌ์ŠคํŠธ ํ•ญ๋ชฉ๋“ค์˜ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋„๋ก ํ•œ๋‹ค.

 

 

  • AnadoridManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.smartfan">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Settings_Advice"></activity>
	<!— SubActivity ์ž…๋ ฅ —>
        <activity android:name=".Settings_Voice" />
        <activity android:name=".Settings_Temperature" />
        <activity android:name=".Settings_Widget" />
        <activity android:name=".MainActivity" />
        <activity android:name=".IntroActivity">

            <!-- ํŠน์ • intent๋ฅผ ๋ฐ›์„์ง€ ๋ง์ง€ ์ •ํ•˜๋„๋ก intnet-filter๋ฅผ ์ž…๋ ฅ -->
            <intent-filter>
                <!-- action_main : ์‹œ์ž‘ ์•กํ‹ฐ๋น„ํ‹ฐ๋ฅผ ์ง€์ •ํ•˜๋Š” ์•ก์…˜ -->
                <action android:name="android.intent.action.MAIN" />
                <!-- category_LAUNCHER : ์• ํ”Œ๋ฆฌ ์ผ€์ด์…˜์—์„œ ๊ฐ€์žฅ ๋จผ์ € ์‹คํ–‰๋˜๋Š” ์•กํ‹ฐ๋น„ํ‹ฐ -->
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

intent-filter๋ฅผ ์‚ฌ์šฉํ•ด ํŠน์ • intent๋ฅผ ๋ฐ›์„์ง€ ๋ง์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•œ ํ›„,

intent๋ฅผ ํ†ตํ•ด ํ™”๋ฉด์ด ์ „ํ™˜๋  ์ˆ˜ ์žˆ๋„๋ก SubActivity๋“ค์„ ์ž…๋ ฅํ•ด ์ฃผ๋„๋ก ํ•œ๋‹ค.

 

 

 

์• ๋ฎฌ๋ ˆ์ดํ„ฐ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด ๋ณด๋ฉด

๊ฐ ๋ฆฌ์ŠคํŠธ์˜ ๊ฐ ํ•ญ๋ชฉ๋“ค์„ ํด๋ฆญํ–ˆ์„ ๊ฒฝ์šฐ

๊ฐ ํ™”๋ฉด ํŽ˜์ด์ง€๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 


 

 

 

๋“œ๋””์–ด fragment์—์„œ listView๋ฅผ ๋งŒ๋“ค์–ด ๊ฐ ํ•ญ๋ชฉ์˜ ํŽ˜์ด์ง€๊นŒ์ง€ ๋งŒ๋“ค์–ด ๋ณด์•˜๋‹ค.

 

์ด์ „์— ๋ฏธ๋ฆฌ ์„ค์ •์„ ๋‹ค ํ•ด๋‘์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํฐ ๊ณผ์ •์€ ์—†์—ˆ์ง€๋งŒ ๊ทธ๋ž˜๋„ ๋ฟŒ๋“ฏํ•˜๋‹ค.

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€