인프런 커뮤니티 질문&답변

Tkhp Sch님의 프로필 이미지

작성한 질문수

1:1채팅 만들기(Android + Kotlin + Firebase)

RecyclerView

RecyclerView 7분중 GroupieViewHolder 자동입력과 UserItem을 Implement Members하는법을 모르겠어요.

작성

·

315

0

1:1채팅 만들기(Android + Kotlin + Firebase)

RecyclerView 7분

ChatListActivity.kt

package com.example.chatting_video

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_chat_list.*

class ChatListActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.
activity_chat_list)

val adapter = GroupAdapter<GroupieViewHolder>
오류코드
e: C:\Users\MS\AndroidStudioProjects\chatting_video\app\src\main\java\com\example\chatting_video\ChatListActivity.kt: (12, 23): Unresolved reference: GroupAdapter

LoginActivity
package com.example.chatting_video

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.example.chatting_video.R
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_login.*

class LoginActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth

private val TAG = LoginActivity::class.java.simpleName


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)

auth = FirebaseAuth.getInstance()

login_button.setOnClickListener {

val email = login_email.text.toString()
val password = login_password.text.toString()

auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithEmail:success")

//데이터베이스에 유저 정보 넣어줘야 합니다.

val intent = Intent(this, ChatListActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)

} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithEmail:failure", task.exception)

}
}
}
}
}

MainActivity
package com.example.chatting_video

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
import android.util.Log as Log
import kotlinx.android.synthetic.main.activity_main.login_button_main as login_button_main


class MainActivity : AppCompatActivity() {

private lateinit var auth: FirebaseAuth
// ...
// Initialize Firebase Auth


private val TAG: String = MainActivity::class.java.simpleName


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

auth = FirebaseAuth.getInstance()

join_button.setOnClickListener {

val user = hashMapOf(
"first" to "Ada",
"last" to "Lovelace",
"born" to 1815
)
val email = email_area.text.toString()
val password = password_area.text.toString()
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information

Log.d(TAG, "성공")

val uid = FirebaseAuth.getInstance().uid


// Create a new user with a first and last name
val user = hashMapOf(
"first" to "Ada",
"last" to "Lovelace",
"born" to 1815
)

// Add a new document with a generated ID




val intent = Intent(this, ChatListActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)


} else {

Log.d(TAG, "실패", task.exception)


}
}
}




login_button_main.setOnClickListener {

val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)


}



}


}
여기선 성공 실패 코드를 지운게 있어요. 넣으면 오류가 걸려서 지웠어요.
// Add a new document with a generated ID
db
.collection("users")
   
.add(user)
   
.addOnSuccessListener { documentReference ->
       
Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}")
   
}
   
.addOnFailureListener { e ->
       
Log.w(TAG, "Error adding document", e)
   
}
db.이부분이 빨간색이 되었어요. 어떻게 해야하나요?

User
ackage com.example.chatting_video

class User(val uid : String, val username : String)

UserItem.kt
package Model

import android.content.ClipData

class UserItem : ClipData.Item<GroupieViewHolder>(){

}

여기에서는 GroupieViewHolder라는 명령어가 자동입력이 되지 않고 빨간색이 뜹니다.

activity_chat_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:id="@+id/recyclerview_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChatListActivity">

<androidx.recyclerview.widget.RecyclerView
android:layout_width="344dp"
android:layout_height="572dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="40dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.761"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.632" />
</androidx.constraintlayout.widget.ConstraintLayout>

여기서는 app:layoutManager="android.recyckerview.widget.LinearLayoutManager"를 넣었습니다.

activity_login.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:background="#a6d8fe"
tools:context=".LoginActivity">


<EditText
android:id="@+id/login_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="login_email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="login_password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_email" />

<Button
android:id="@+id/login_button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="login_button"
android:background="#fb7606"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login_password" />

</androidx.constraintlayout.widget.ConstraintLayout>

activity_main.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:background="#a6d8fe"
tools:context=".MainActivity">

<EditText
android:id="@+id/UserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="UserName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/email_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="email_area"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/UserName" />

<EditText
android:id="@+id/password_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="password_area"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/email_area" />

<Button
android:id="@+id/join_button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="join_button"
android:background="#fb7606"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password_area" />

<Button
android:id="@+id/login_button_main"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:text="login_button"
android:background="#fb7606"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/join_button" />


</androidx.constraintlayout.widget.ConstraintLayout>
message_list_row.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="80dp">

<TextView
android:layout_width="73dp"
android:layout_height="26dp"
android:layout_margin="20dp"
android:text="name"
tools:layout_editor_absoluteX="10dp"
tools:layout_editor_absoluteY="30dp">

</TextView>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="message"
tools:layout_editor_absoluteX="130dp"
tools:layout_editor_absoluteY="30dp">

</TextView>

</androidx.constraintlayout.widget.ConstraintLayout>

name message
name message
name message
이게 어떻게 뜨는지 궁금해요.


video\app\src\main\java\com\example\chatting_video\ChatListActivity.kt: (12, 23): Unresolved reference: GroupAdapter
e: C:\Users\MS\AndroidStudioProjects\chatting_video\app\src\main\java\com\example\chatting_video\MainActivity.kt: (36, 13): Unresolved reference: db

이런오류들을 어떻게 해결해야 하나요?

val adapter = GroupAdapter<GroupieViewHolder>를 인력하면 빨간색으로 떠요
자동입력이 안되요.

implementation "com.xwray:groupie:$groupie_version"

2.9.0은 어떻게 입력하는 것인가요? 이걸 그대로 입력하면 오류가 떠요.

GroupAdapter와 GroupieViewHolder가 입력되는 부분이 없어서 빨간색 오류가 뜨고, 실행이 안되요. 무슨 코드를 추가해야 이것들이 자동 입력이 되나요?

그리고 수업강의하실때 만들었던 원본 파일있으시면 공유가능할까요? 제거랑 비교하면서 코드를 짜려고요.




답변 3

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

com.xwray:groupie:$groupie_version

이 부분이 아니라

com.xwray:groupie:$2.7.0

처럼 버전을 명시해주세요~

0

Tkhp Sch님의 프로필 이미지
Tkhp Sch
질문자

복사하기 붙여넣기를 말하는건가요?

implementation "com.xwray:groupie:$groupie_version"를 붙여넣기 하라는 말인가요?
자세하게 설명부탁드립니다.

0

개복치개발자님의 프로필 이미지
개복치개발자
지식공유자

강의 기준 3:19에서 implemetation을 해주세요 ~

Tkhp Sch님의 프로필 이미지

작성한 질문수

질문하기