I'm new in Android. I'm developing an application that display 10 words and their meaning one by one. My question is how do i display data one by one from Model View which contain LiveData<List< >> variable to Text View .
The process should by like this: retrieving data from database to Repository to View Model and finally display it in UI Text View. Any suggestion except using Recycle View?
.
@Entity(tableName = "word_table")
data class Word(
@ColumnInfo(name = "English")
val English: String,
@ColumnInfo(name = "Italian")
val Italian: String
)
{
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
var id: Int = 0
fun Word(id: Int) {
this.id = id
}
@Dao
interface WordDao {
@Query("SELECT * FROM word_table ")
fun getWords(): Flow<List<Word>>
class WordRepository(private val wordDao: WordDao) {
val allWords: Flow<List<Word>> = wordDao.getWords()
}
class WordViewModel(private val repository: WordRepository) : ViewModel() {
val allWords: LiveData<List<Word>> = repository.allWords.asLiveData()
}
}