如何删除 TextView 中两个相同字符串值之一?
How to remove one of the two identical string value in a TextView?
我正在开发一个 android 应用程序来读取 RFID 标签号并将其显示在文本视图中。但是如果再次读取相同的标签号,我只想在第二个 textView 中显示一次。
考虑到第一个 Textview 多次包含标签号,我该怎么做才能在第二个 TextView 中显示一次标签号?
这是我编写的用于在第二个 textView 中显示的代码:
rfidTagNo = textView.getText().toString().replaceAll("\s","");
TextView rfid;
rfid = (TextView)findViewById(R.id.rfidTag);
rfid.setText(rfidTagNo);
此外,我想在第二个 textView 中只显示标签号,而不是第一个 TextView 中显示的任何消息,例如 "approximate your card to the reader"。
在您写第一个 TextView
之前,将您的标签保存在 ArrayList<String>
中。
ArrayList<String> myTags = new ArrayList<>();
// fetch tags
myTags.add(currentTag);
// set text to first `TextView` & check if it is already added
if (!myTags.contains(currentTag)) {
rfid.setText(currentTag);
}
我正在开发一个 android 应用程序来读取 RFID 标签号并将其显示在文本视图中。但是如果再次读取相同的标签号,我只想在第二个 textView 中显示一次。
考虑到第一个 Textview 多次包含标签号,我该怎么做才能在第二个 TextView 中显示一次标签号?
这是我编写的用于在第二个 textView 中显示的代码:
rfidTagNo = textView.getText().toString().replaceAll("\s","");
TextView rfid;
rfid = (TextView)findViewById(R.id.rfidTag);
rfid.setText(rfidTagNo);
此外,我想在第二个 textView 中只显示标签号,而不是第一个 TextView 中显示的任何消息,例如 "approximate your card to the reader"。
在您写第一个 TextView
之前,将您的标签保存在 ArrayList<String>
中。
ArrayList<String> myTags = new ArrayList<>();
// fetch tags
myTags.add(currentTag);
// set text to first `TextView` & check if it is already added
if (!myTags.contains(currentTag)) {
rfid.setText(currentTag);
}