当我从数据库中获取数据时,由于数据格式不正确,出现了很多空格。如何在此代码中使用 .trim() 方法。
@Override
public void onStart() {
super.onStart();
groupDeals.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@javax.annotation.Nullable DocumentSnapshot documentSnapshot, @javax.annotation.Nullable FirebaseFirestoreException e) {
if (e != null) {
return;
}
if (documentSnapshot.exists()) {
String grpDealsDetails = documentSnapshot.getString(GROUP_DEALS_KEY_DEALS);
if (TextUtils.isEmpty(grpDealsDetails)) {
tv_groupDeals.setText("Not Available");
} else {
Spanned descripti;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
descripti = Html.fromHtml(grpDealsDetails, Html.FROM_HTML_MODE_LEGACY);
} else {
descripti = Html.fromHtml(grpDealsDetails);
}
tv_groupDeals.setText(descripti);
tv_groupDeals.setMovementMethod(LinkMovementMethod.getInstance());
}
}
}
}
);
}
最佳答案
设置之前tv_groupDeals.setText(descripti);
您可以添加 descripti= descripti.trim();
关于java - 如何在此代码中使用 .trim() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60736603/