@Override public void onRFDData(TagData[] tagData) { requireActivity().runOnUiThread(new Runnable() { @Override public void run() { if (tagData != null && tagData.length > 0) { for (TagData tag : tagData) { String rfidNO = tag.getTagID(); if (rfidNO.startsWith("40") && !tags.contains(rfidNO)) { tags.add(rfidNO); String hex = rfidNO.replaceAll("40", ""); if (!hex.isEmpty()) { try { String code = RSAEncryptProvider.hexToAscii(hex); if (code.length() > 10) { String sn = code.substring(code.length() - 7); // 7位序列号 String style = code.substring(code.length() - 10, code.length() - 7); // 3位款式 String spec = code.substring(0, code.length() - 10); // 型号 ExcelImportViewModel m = iv.inventoryList.stream().filter(t -> t.spec.equalsIgnoreCase(spec) && t.style.equalsIgnoreCase(style)).findFirst().orElse(null); if (m != null) { m.check_inventory += 1; if (m.check_inventory == m.real_inventory) { m.status = 1; // } else if (m.check_inventory > m.real_inventory) { m.status = 2; } } } } catch (Exception ex) { } } } } updateView(); } } }); }如何将 String sn = code.substring(code.length() - 7); // 7位序列号 String style = code.substring(code.length() - 10, code.length() - 7); // 3位款式 String spec = code.substring(0, code.length() - 10); 展示到一个新的页面
时间: 2024-03-03 07:47:59 浏览: 23
要将这三个字符串展示到一个新的页面中,可以通过Intent和Bundle来传递数据。具体实现步骤如下:
1.在当前页面中创建一个新的按钮或者点击事件,用于跳转到新的页面。
2.在当前页面中获取三个字符串的值,并将它们存储到Bundle中:
```
Bundle bundle = new Bundle();
bundle.putString("sn", sn);
bundle.putString("style", style);
bundle.putString("spec", spec);
```
3.创建一个新的Intent对象,并将Bundle作为参数传递给它:
```
Intent intent = new Intent(getActivity(), NewActivity.class);
intent.putExtras(bundle);
startActivity(intent);
```
4.在新的页面中获取传递过来的Bundle,并从中获取三个字符串的值:
```
Bundle bundle = getIntent().getExtras();
String sn = bundle.getString("sn");
String style = bundle.getString("style");
String spec = bundle.getString("spec");
```
5.将这三个字符串展示在新的页面中的TextView或者其他控件中即可。
相关问题
public class InventoryRFID implements RfidEventsListener { @Override public void eventReadNotify(RfidReadEvents rfidReadEvents) { TagData[] tags = reader.Actions.getReadTags(500); if (tags == null) { return; } for (final TagData tag : tags) { startBeepingTimer(); if (epcList.add(tag.getTagID())) { runOnUiThread(new Runnable() { @Override public void run() { String epc = tag.getTagID(); if (epc.startsWith("40")) { String hexEpc = hexToAscii(epc); Log.e("tag", tag.getTagID()); reader(hexEpc); } } }); } } }怎么使用 Handler 避免并发修改 UI。
可以使用 Handler 来避免并发修改 UI,具体步骤如下:
1. 创建 Handler 对象,并在主线程中进行实例化。
2. 在 runOnUiThread 中,使用 Handler 发送一条消息,让其在主线程中更新 UI。
3. 在 Handler 中处理消息,更新 UI。由于 Handler 在主线程中运行,所以不会出现并发修改 UI 的问题。
修改后的代码如下:
```
public class InventoryRFID implements RfidEventsListener {
private Handler mHandler = new Handler(Looper.getMainLooper());
@Override
public void eventReadNotify(RfidReadEvents rfidReadEvents) {
TagData[] tags = reader.Actions.getReadTags(500);
if (tags == null) {
return;
}
for (final TagData tag : tags) {
startBeepingTimer();
if (epcList.add(tag.getTagID())) {
mHandler.post(new Runnable() {
@Override
public void run() {
String epc = tag.getTagID();
if (epc.startsWith("40")) {
String hexEpc = hexToAscii(epc);
Log.e("tag", tag.getTagID());
reader(hexEpc);
}
}
});
}
}
}
}
```
@Override public void onRFDData(TagData[] tagData) { requireActivity().runOnUiThread(new Runnable() { @Override public void run() { if (tagData != null && tagData.length > 0) { for (TagData tag : tagData) { String rfidNO = tag.getTagID(); if (rfidNO.startsWith("40") && !tags.contains(rfidNO)) { tags.add(rfidNO); String hex = rfidNO.replaceAll("40", ""); if (!hex.isEmpty()) { try { String code = RSAEncryptProvider.hexToAscii(hex); if (code.length() > 10) { String sn = code.substring(code.length() - 7); // 7位序列号 String style = code.substring(code.length() - 10, code.length() - 7); // 3位款式 String spec = code.substring(0, code.length() - 10); // 型号 ExcelImportViewModel m = iv.inventoryList.stream().filter(t -> t.spec.equalsIgnoreCase(spec) && t.style.equalsIgnoreCase(style)).findFirst().orElse(null); if (m != null) { m.check_inventory += 1; if (m.check_inventory == m.real_inventory) { m.status = 1; // } else if (m.check_inventory > m.real_inventory) { m.status = 2; } } } } catch (Exception ex) { } } } } updateView(); } } }); }什么意思
这段代码是在 Android 应用中用于处理 RFID 标签数据的方法。当有新的标签数据传入时,它会遍历标签数据数组,将标签 ID 转换成字符串并去掉前缀 "40",再将字符串转换成特定编码的文本,然后根据文本中的序列号、款式、型号等信息在一个 Excel 表格中查找对应的记录,并更新记录的相关信息,例如增加已盘点数量、更新状态等。最后,它会调用 `updateView()` 方法,更新界面显示。