Я пытаюсь заставить работать свое первое приложение для Android с помощью jotlin.
Я следую https://aws.amazon.com/getting-started/hands-on/build -android-app-amplify/
Похоже, что этот пример немного старше кода, который я использую. В частности, в моем build.gradle есть раздел
buildFeatures {
viewBinding true
}
Я внес изменения, которые, по моему мнению, . По крайней мере, теперь он компилируется и работает.
В файле журнала я вижу RecyclerView -->Адаптер не подключен; пропуск макета. Я также не вижу верхнюю панель инструментов, как ожидалось.
Вот связанные файлы
MainActivity.kt
package me.paries.framewithaws
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.RecyclerView
import me.paries.framewithaws.databinding.ActivityMainBinding
import me.paries.framewithaws.databinding.ContentMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var contentMainBinding: ContentMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setSupportActionBar(binding.toolbar)
contentMainBinding = ContentMainBinding.inflate(layoutInflater);
setupRecyclerView(contentMainBinding.itemList)
}
private fun setupRecyclerView(recyclerView: RecyclerView) {
UserData.notes().observe(this, Observer { notes ->
Log.d(TAG, "Note observer received ${notes.size} notes")
// let's create a RecyclerViewAdapter that manages the individual cells
recyclerView.adapter = NoteRecyclerViewAdapter(notes)
})
}
companion object {
private const val TAG = "MainActivity"
}
}
activity_main.xml
NoteRecyclerViewAdapter.kt
package me.paries.framewithaws
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
// this is a single cell (row) in the list of Notes
class NoteRecyclerViewAdapter(
private val values: MutableList?) :
RecyclerView.Adapter() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.content_note, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = values?.get(position)
holder.nameView.text = item?.name
holder.descriptionView.text = item?.description
if (item?.image != null) {
holder.imageView.setImageBitmap(item.image)
}
}
override fun getItemCount() = values?.size ?: 0
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val imageView: ImageView = view.findViewById(R.id.image)
val nameView: TextView = view.findViewById(R.id.name)
val descriptionView: TextView = view.findViewById(R.id.description)
}
}
content_main.xml
content_note.xml
Подробнее здесь: https://stackoverflow.com/questions/788 ... attached-s
Попробуйте запустить первое приложение для Android, получите ошибку «Адаптер не подключен; пропуск макета» ⇐ Android
Форум для тех, кто программирует под Android
1722722992
Anonymous
Я пытаюсь заставить работать свое первое приложение для Android с помощью jotlin.
Я следую https://aws.amazon.com/getting-started/hands-on/build -android-app-amplify/
Похоже, что этот пример немного старше кода, который я использую. В частности, в моем build.gradle есть раздел
buildFeatures {
viewBinding true
}
Я внес изменения, которые, по моему мнению, . По крайней мере, теперь он компилируется и работает.
В файле журнала я вижу [b]RecyclerView -->Адаптер не подключен; пропуск макета[/b]. Я также не вижу верхнюю панель инструментов, как ожидалось.
Вот связанные файлы
[b]MainActivity.kt[/b]
package me.paries.framewithaws
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.RecyclerView
import me.paries.framewithaws.databinding.ActivityMainBinding
import me.paries.framewithaws.databinding.ContentMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var contentMainBinding: ContentMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setSupportActionBar(binding.toolbar)
contentMainBinding = ContentMainBinding.inflate(layoutInflater);
setupRecyclerView(contentMainBinding.itemList)
}
private fun setupRecyclerView(recyclerView: RecyclerView) {
UserData.notes().observe(this, Observer { notes ->
Log.d(TAG, "Note observer received ${notes.size} notes")
// let's create a RecyclerViewAdapter that manages the individual cells
recyclerView.adapter = NoteRecyclerViewAdapter(notes)
})
}
companion object {
private const val TAG = "MainActivity"
}
}
[b]activity_main.xml[/b]
[b]NoteRecyclerViewAdapter.kt[/b]
package me.paries.framewithaws
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
// this is a single cell (row) in the list of Notes
class NoteRecyclerViewAdapter(
private val values: MutableList?) :
RecyclerView.Adapter() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.content_note, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = values?.get(position)
holder.nameView.text = item?.name
holder.descriptionView.text = item?.description
if (item?.image != null) {
holder.imageView.setImageBitmap(item.image)
}
}
override fun getItemCount() = values?.size ?: 0
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val imageView: ImageView = view.findViewById(R.id.image)
val nameView: TextView = view.findViewById(R.id.name)
val descriptionView: TextView = view.findViewById(R.id.description)
}
}
[b]content_main.xml[/b]
[b]content_note.xml[/b]
Подробнее здесь: [url]https://stackoverflow.com/questions/78829878/try-to-get-first-android-app-to-work-getting-the-error-no-adapter-attached-s[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия