-
카테고리
-
해결 여부
미해결
recyclerview 어댑터 관련해서 질문 남깁니다!
18.09.27 02:44 작성 조회수 268
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
이 오류도 뜨네요...^^
답변을 작성해보세요.
0
0
0
답변 3