inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Từ Kotlin Android đến máy chủ Firebase và tạo ra Chatbot tuyệt vời

Mục tiêu của bài giảng này

recyclerview 어댑터 관련해서 질문 남깁니다!

510

choco12343

3 câu hỏi đã được viết

0

import ai.api.AIConfiguration.SupportedLanguages.Korean
import ai.api.AIConfiguration.SupportedLanguages.fromLanguageTag
import ai.api.android.AIConfiguration
import ai.api.AIDataService
import ai.api.model.AIRequest
import ai.api.model.Result
import android.os.AsyncTask
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.EditText
import org.techtown.food_menu.R.id.chatText
import org.techtown.food_menu.adapter.ChatAdapter
import org.techtown.food_menu.adapter.MessageDTO
import java.util.ArrayList

class ChatActivity : AppCompatActivity() {
    var messageDTOs = arrayListOf<MessageDTO>()
    var aiDataService : AIDataService? = null
    private val recyclerview: RecyclerView? = null
    private val Adapter: ChatAdapter? = null
    private val llm: LinearLayoutManager? = null
    private val editText: EditText? = null
    private final var lang : ai.api.AIConfiguration.SupportedLanguages? = null

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

        recyclerview?.findViewById<View>(R.id.chat_recyclerview)
        recyclerview?.adapter = Adapter
        recyclerview?.layoutManager = llm
        editText?.findViewById<View>(R.id.chatText)

        val btn = findViewById<View>(R.id.button) as Button
        btn.setOnClickListener {
            if (!TextUtils.isEmpty(editText?.text)) {
                messageDTOs!!.add(MessageDTO(true, editText?.text.toString()))
                Adapter!!.notifyDataSetChanged()
                recyclerview?.smoothScrollToPosition(messageDTOs.size - 1)
                TalkAsyncTask().execute(editText?.text.toString())
                editText?.setText("")
            }
        }

        var config = AIConfiguration("일부러 지웟어요",Korean,AIConfiguration.RecognitionEngine.System)
        aiDataService = AIDataService(config)
    }

    inner class TalkAsyncTask:AsyncTask<String, Void, Result>() {
        override fun doInBackground(vararg params: String?): Result {
            var aiRequest = AIRequest()
            aiRequest.setQuery(params[0])

            return aiDataService!!.request(aiRequest).result
        }

        override fun onPostExecute(result: Result?) {
            if (result != null) {
                makeMessage(result)
            }
        }
    }

    fun makeMessage(result: Result?) {
        var speech = result?.fulfillment?.speech
        messageDTOs.add(MessageDTO(false, speech))
        recyclerview?.adapter?.notifyDataSetChanged()
        recyclerview?.smoothScrollToPosition(messageDTOs.size - 1)
    }
}

}

이 코드인데 하울님이 하신대로 메인액티비티에서 따라할 때는 recyclerview.adpater 이렇게 해도 어댑터 연결이 잘되던 것이 프로젝트를 합치기 위해서 메인액티비티에서 인텐트로 연결되는 ChatActivity에서 하려니까 잘 되지 않았어요 그래서 이 코드대로 했는데 E/RecyclerView: No adapter attached; skipping layout 이 오류가 뜬다고 합니다ㅠㅠ 혹시 이 문제가 MainActivity가 아니어서 그런건가요? 해결 방법 알려주시면 감사하겠습니다ㅠㅠ
E/memtrack: Couldn't load memtrack module
09-26 18:26:41.770 1904-1917/? W/android.os.Debug: failed to get memory consumption info: -1
이 오류도 뜨네요...^^

android chatbot kotlin

Câu trả lời 3

0

you68780911

코드를 확인해보니 llm 값이 null값인듯 하네요..

0

choco12343

아.... adapter라는 폴더 안에 넣어놨어요 그래서 그런거일까요?

0

you68780911

흠.. 어뎁터의 위치가 잘못된듯 합니다 혹시 어뎁터가 어디에 있나요?

개인정보보호 설정에 의해 이 동영상은 Vimeo에서 재생할 수 없습니다.

0

1239

0

환불도 안되는건가요?

0

250

0

Nested data class 문의 드립니다.

0

228

1

CoordinatorLayout 도 강의해주세용^^

0

282

1

구글 로그인 옵션 요청에서

0

338

2

정말로 버전 차이가 많이 나는것 같습니다. 꼭 답변 부탁 드립니다

0

220

1

각 객체를 사용하는 이유와 방법의 설명이 없어서 안드로이드 처음하는 사람은 어렵네요

0

178

0

프로젝트 실행 시 "Caused by: java.net.SocketException: Connection reset" 라는 에러가 뜨는데 이게 뭔가요?

0

476

0

회원가입은되는데 로그인은 되지않습니다.

0

281

1

혹시 답변 부분에 하이퍼링크 추가할 수 있는 방법은 아녜 없는건가요?

0

514

1

edit_text에 글이 set되는 것은 비동기식으로 작동하는 건가요?

0

197

1

Type mismatch error

0

298

1

혹시 자바로 만들어진 안드로이드 프로젝트 안에 코틀린 파일을 쓸 수 있나요?

0

297

1

풀필먼트를 호출하고 결과를 받아오는 방법...

0

274

1

애는굳이 마법봉 안쓰는 이유가있나요?

0

243

1

기존으로 만들때 <RelativeLayout으로 시작하지 않고 <android.support.constraint.ConstraintLayout로 시작됩니다

0

204

1

여기서 toString이 무슨 역할을 하는지 잘 모르겠습니다.

0

238

1

질문드립니다.

0

173

1

질문드립니다.

0

185

1

질문드립니다.

0

168

1

질문드려요~

0

172

1

nested class의 subject는 Subject가 아니여도 인식하나요?

0

146

1

제어문 강의 예제 질문입니다

0

282

1

recyclerview 의 onBindViewHolder 안에서 overridePendingTransition 를 적용할수 있나용?

0

436

2