Android 如何将侦听器添加到文本视图,而不是在文本更改时调用方法。文本视图是卡片视图的一部分
在这段代码中,mytest是卡片视图中的文本视图Android 如何将侦听器添加到文本视图,而不是在文本更改时调用方法。文本视图是卡片视图的一部分,android,android-cardview,Android,Android Cardview,在这段代码中,mytest是卡片视图中的文本视图 cards item = new cards(dataSnapshot.getKey(), dataSnapshot.child("name").getValue().toString(), mytest, profileImageUrl); rowItems.add(item); arrayAdapter.notifyDat
cards item = new cards(dataSnapshot.getKey(), dataSnapshot.child("name").getValue().toString(), mytest, profileImageUrl);
rowItems.add(item);
arrayAdapter.notifyDataSetChanged();
正如我所理解的,您应该在Kotlin中实现如下示例所示的TextWatcher:
class MyTextWatcher() : TextWatcher {
override fun afterTextChanged(editable: Editable?) {
//Do something
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
//Do something
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
//Do something
}
}
然后将其附加到所需的TextView,如下所示:
yourTextView.addTextChangedListener(MyTextWatcher)
由于TextView是一个不可变字段,我认为您不能添加TextChangedListener
但是,如果您想查看EditText的更改,请查看TextWatcher:您能否更具体地说明您在尝试使用mytest文本视图的值更新另一个文本视图时遇到的困难。当新卡在视图中时,很难得到更新的值。仍然显示第一个卡视图值。