[英]New TextView created when using setText to a TextView
I have a TextView
in my Android app . 我的Android应用程序中有一个
TextView
。 When I use setText()
to the old text of the TextView
still appear and the new text is written on it. 当我使用
setText()
到TextView
的旧文本时,仍然会出现新的文本。 If I close the screen of the phone and opens it after a small period of time the old text of TextView
disappeared. 如果我关闭手机的屏幕并在一段时间后将其打开,则
TextView
的旧文本会消失。
How can I solve that? 我该如何解决?
The grey is the old text of TextView
and the green is the new text of the TextView
灰色是旧文本
TextView
和绿色是新文本TextView
this is the xml code : 这是xml代码:
<TextView
android:id="@+id/challengeStateInResultActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="5dp"
android:background="@color/gray"
android:padding="7dp"
android:text="جارى التحميل ..."
android:textColor="@color/white"
android:textSize="20sp" />
and this is the presenter code : 这是演示者代码:
fireStoreChallenges.document(challengeId).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
final DocumentSnapshot documentSnapshot = task.getResult();
final long opponentScore = documentSnapshot.getLong("player1score");
String player1uid = documentSnapshot.getString("player1Uid");
fireStoreUsers.document(player1uid).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
String opponentName = document.getString("userName");
String opponentImage = document.getString("userImage");
view.setOpponentData(opponentScore, opponentName, opponentImage);
}
}
});
int opponentScoreInt = (int) opponentScore;
if (score == opponentScoreInt) {
view.setChallengeTvText(drawChallengeText);
} else {
if (score > opponentScoreInt) {
view.setChallengeTvText(wonChallengeText);
view.setChallengeTvBGColor(context.getResources().getColor(R.color.green));
} else {
view.setChallengeTvText(loseChallengeText);
view.setChallengeTvBGColor(context.getResources().getColor(R.color.red));
}
}
}
}
});
and this is the method in the view : 这是视图中的方法:
@Override
public void setChallengeTvText(String text) {
challengeStateTv.setText(text);
challengeStateTv.invalidate();
}
To update the previous text,you can update the TextView with 要更新以前的文本,您可以使用
TextView.setText("NEW_TEXT");
Code Example: 代码示例:
TextView tv;
// inside OnCreate method
tv = (TextView) findViewById(R.id.TextView) // link to your xml TextView Definition
// to clear the TextView you can use as below
// tv.setText("");
// to set Text as "Hello"
tv.setText("Hello");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.