I am trying to create a small game with the following components:
- 9 cells - in a GridView
- some words (that have to be introduced in the table, each on a cell)
- TextToSpeech - on each cell
Each single cell contains one single word and the user has to choose one of the words displayed below in order to complete the cell (2 words are supposed to be in a cell). Everything works perfectly, the only problem is that the TextToSpeech is being activated once the user chooses the right word, but I would want it to be one step forward. That means, once the user chooses the right word for ONE cell, the TextToSpeech should be automatically activated for the NEXT cell, so once the user has chosen the right word, he should hear the next word from the next cell.
These cells don't have ids, they are in the MainActivity, like this:
private fun setData() {
dataBeanArrayList = ArrayList<CellDataBean>()
val cellDataBean = CellDataBean()
//we store in the var cellDataBean both texts
//according to the class CellDataBean
cellDataBean.text_one = "Hello"
cellDataBean.text_two = "World"
dataBeanArrayList!!.add(cellDataBean)
val cellDataBean1 = CellDataBean()
cellDataBean1.text_one = "Okay"
cellDataBean1.text_two = "Not bad"
If I implement a new text view (which is not preferable), the TextToSpeech only works like I want for the first cell, once you press on this:
starttv.setOnClickListener {
if (count == 0) {
isstart = true
val text: String = dataBeanArrayList[count].text_1
textToSpeech!!.speak(text, TextToSpeech.QUEUE_FLUSH, null)
dataBeanArrayList[count].isSelected = true
cellAdapter!!.notifyDataSetChanged()
}
}
I am trying to implement something like: (where 'mainbacklay' is the ID from the cell)
when(vh.mainbacklay)[position]==0{
// here the text to speech should be enabled for the text from the second cell with the position 1
}
So when the position 2 from the cell is activated, the text to speech should be enabled for the text with the third position and so on.
Could someone help me figure this out, please? Thank you.