
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
3주차 5강 수강후 앱 실행에 관한질문입니다.
에러 없이 정상 실행이 되었지만 시간대별 더미리스트가 출력되지 않습니다.

FirstFragment

작성한 코드 및 에러 메세지
WeatherFragmentStateAdapter.kt
package com.example.spartaweatherapp
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
class WeatherFragmentStateAdapter(activity: AppCompatActivity) : FragmentStateAdapter(activity) {
override fun getItemCount() = 2
override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> FirstFragment()
else -> SecondFragment()
}
}
class SecondFragment :Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_weather_list, container, false)
}
}
class FirstFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_weather_home, container, false)
}
}
}
-------------------------------------------
fragment_weather_list.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"
tools:context=".WeatherListFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/top_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/top_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/region_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:text="@string/seoul"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/weather_status_iv"
android:layout_width="100dp"
android:layout_height="70dp"
android:layout_marginEnd="20dp"
android:contentDescription="@+id/weather_status_iv"
android:src="@drawable/ic_color_sunny_cloudy"
app:layout_constraintBottom_toBottomOf="@id/main_temper_tv"
app:layout_constraintEnd_toStartOf="@id/main_temper_tv"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/main_temper_tv" />
<TextView
android:id="@+id/main_temper_tv"
android:layout_width="wrap_content"
android:layout_height="128dp"
android:text="@string/three"
android:contentDescription="@+id/main_temper_tv"
android:textColor="#FFFFFF"
android:textSize="90sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/weather_status_iv"
app:layout_constraintTop_toBottomOf="@id/region_text" />
<ImageView
android:id="@+id/ic_temp_view"
android:layout_width="16dp"
android:layout_height="16dp"
android:contentDescription="@+id/ic_temp_view"
android:src="@drawable/ic_temperature"
app:layout_constraintBottom_toBottomOf="@id/main_temper_tv"
app:layout_constraintStart_toEndOf="@id/main_temper_tv"
app:layout_constraintTop_toTopOf="@id/main_temper_tv"
app:layout_constraintVertical_bias="0.2" />
<TextView
android:id="@+id/main_weather_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:text="@string/cloudy"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@id/main_temper_tv"
app:layout_constraintStart_toStartOf="@id/main_temper_tv"
app:layout_constraintTop_toBottomOf="@id/weather_status_iv" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/list_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/list_background"
android:paddingHorizontal="24dp"
android:paddingVertical="35dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.68"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="@+id/ic_time_weather_view"
android:layout_width="12dp"
android:layout_height="12dp"
android:contentDescription="@+id/ic_time_weather_view"
android:src="@drawable/ic_sun"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/main_time_weather_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:includeFontPadding="true"
android:text="@string/time_weather"
android:textColor="#9DA7AE"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@id/ic_time_weather_view"
app:layout_constraintStart_toEndOf="@id/ic_time_weather_view"
app:layout_constraintTop_toTopOf="@id/ic_time_weather_view"
app:layout_constraintVertical_bias="0.5" />
<LinearLayout
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="30dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/main_time_weather_text">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/time"
android:textSize="14sp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/Weather"
android:textSize="14sp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/temper"
android:textSize="14sp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/raine"
android:textSize="14sp" />
</LinearLayout>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginHorizontal="11dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/weather_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginHorizontal="11dp"
android:layout_marginBottom="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintBottom_toBottomOf="parent"
tools:listitem="@layout/item_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
-----------------------------------------
WeatherListFragment.kt
package com.example.spartaweatherapp
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.spartaweatherapp.databinding.FragmentWeatherListBinding
class WeatherListFragment : Fragment() {
private var _binding: FragmentWeatherListBinding? = nullprivate val binding get() = _binding!!
private val listAdapter by lazy { WeatherItemListAdapter() }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentWeatherListBinding.inflate(inflater, container, false)
val root: View = binding.root
return root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val dataList = WeatherDataList.list
with(binding) {
weatherList.apply {
adapter = listAdapterlayoutManager = LinearLayoutManager(requireContext())
DividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL).apply {
getDrawable(requireContext(), R.drawable.list_divider)?.let { setDrawable(it) }
}.also {
addItemDecoration(it)
}
listAdapter.submitList(dataList.toList())
}
// 임시로 현재 날씨는 0번 Dummy Data로 설정val currentWeather = dataList.get(0)
weatherStatusIv.setImageResource(currentWeather.skyStatus.colorIcon)
mainWeatherText.text = currentWeather.skyStatus.text
mainTemperTv.text = currentWeather.temperature
}
}
}
에러 메시지 없이 정상적 인스톨 되었습니다.
