gpt4 book ai didi

android - EditText 在按下完成后被清除并且表现得很奇怪

转载 作者:行者123 更新时间:2023-11-29 02:25:48 25 4
gpt4 key购买 nike

附加到我的 EditText 是一个 new TextView.OnEditorActionListener()

public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {

if(i == EditorInfo.IME_ACTION_DONE){

dataSnapshot.child("add").child(child.getKey()).child("comment").getRef().setValue(String.valueOf(serviceComment.getText()));
return true;

}else{

return false;

}

}

执行后,当我希望它保留时,我的 EditText 中的文本被清除。

此外,在它被清除后,如果我输入完全相同的内容,代码不会执行并且键盘不会消失,直到我输入与之前输入的内容不同的内容。

我的最终目标是让我的 EditText 中的文本在点击完成并隐藏键盘后保持不变。

这是我的 EditText

的 XML
<EditText
android:id="@+id/txtComment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorSecondary"
android:hint="Enter a comment"
android:imeOptions="actionDone"
android:maxLength="200"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/colorBlack"
android:textSize="14sp" />

最佳答案

要隐藏键盘,您必须在监听器回调中执行此操作:

InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

请尝试一下。

此外,编辑文本清除问题可能是由于以下行造成的:dataSnapshot.child("add").child(child.getKey()).child("comment").getRef().setValue(String.valueOf(serviceComment.getText()));

此行可能会导致 UI 挂起,这可能就是原因。

尝试在另一个线程中调用该操作。

关于android - EditText 在按下完成后被清除并且表现得很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52306761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com