如何通过GridView Base适配器迭代以检查其上的文本?
我已经尝试了不同的方法,我一直坚持尝试数周。 我还尝试在适配器中添加代码,我考虑过使用SQLite,但我只是不知道该怎么做。
我只想检查一个条件,如果该字符串存在于GridView, boolean = true
我可以在活动中做类似的事情吗?
for (i in 0 until arrayList!!.size){
WordViewAdapter(this,arrayList).getView(i, convertView = null, parent = null).word.text
}
}
这是我的网格查看:
这是我的适配器:
private lateinit var mTTS : TextToSpeech
class WordViewAdapter(var ctx: Context, var array: ArrayList<Word_Item>?) : BaseAdapter() {
override fun getCount(): Int {
return array!!.size
}
override fun getItem(position: Int): Any {
return array!![position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var view : View = View.inflate(ctx, R.layout.grid_item_list,null)
var word:TextView = view.findViewById(R.id.tx_word)
var translation:TextView = view.findViewById(R.id.tx_transl)
var wordItem : Word_Item = array!![position]
word.text = wordItem.word
translation.text = wordItem.transl
Translate(ctx).question(word,translation)
view.setOnClickListener{
mTTS = TextToSpeech(ctx, TextToSpeech.OnInitListener { status ->
if (status != TextToSpeech.ERROR){
mTTS.setLanguage(Locale.US)
mTTS.setSpeechRate(0.7F)
mTTS.setPitch(0.7F)
mTTS.speak(word.text.toString(),TextToSpeech.QUEUE_FLUSH,null,null)
}
})
}
return view
}
}
I have tried different ways, I've been stuck trying to do it for weeks.
I also tried to add the code in the adapter, I thought about using sqlite, but I just can't figure how to do it.
I just want to check a condition, if this string exists somewhere in gridview, boolean = true
Can I do something like that in the activity?
for (i in 0 until arrayList!!.size){
WordViewAdapter(this,arrayList).getView(i, convertView = null, parent = null).word.text
}
}
This is my grid view:
This is my Adapter:
private lateinit var mTTS : TextToSpeech
class WordViewAdapter(var ctx: Context, var array: ArrayList<Word_Item>?) : BaseAdapter() {
override fun getCount(): Int {
return array!!.size
}
override fun getItem(position: Int): Any {
return array!![position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var view : View = View.inflate(ctx, R.layout.grid_item_list,null)
var word:TextView = view.findViewById(R.id.tx_word)
var translation:TextView = view.findViewById(R.id.tx_transl)
var wordItem : Word_Item = array!![position]
word.text = wordItem.word
translation.text = wordItem.transl
Translate(ctx).question(word,translation)
view.setOnClickListener{
mTTS = TextToSpeech(ctx, TextToSpeech.OnInitListener { status ->
if (status != TextToSpeech.ERROR){
mTTS.setLanguage(Locale.US)
mTTS.setSpeechRate(0.7F)
mTTS.setPitch(0.7F)
mTTS.speak(word.text.toString(),TextToSpeech.QUEUE_FLUSH,null,null)
}
})
}
return view
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我做到了。我会在这里发布它,也许对某人有帮助。
我已经创建了另一个列表:
和一个函数,该函数检查是否相等,例如,如果可以,请发送到适配器,然后对其进行更新:
in适配器,我只是添加:
Well guys, I did it. And I will post it here, maybe it help someone.
I've created another list:
And a function that check if it is equal, like that, if OK, then send to adapter, and update it:
In the adapter, I just add it: