TextView textView = findViewById(R.id.text_name); // textView.setVisibility(View.GONE);
时间: 2024-06-02 08:12:55 浏览: 13
这段代码是在 Android 中使用 findViewById 方法来获取布局中的 TextView 控件,并将其隐藏(设置为不可见)。具体来说,findViewById 方法是用于获取指定 ID 的控件对象,而 R.id.text_name 则是指定了需要获取的控件的 ID。然后调用 setVisibility 方法将控件设置为不可见,View.GONE 是其中的一个可选值,表示完全不占据空间并且不可见。
相关问题
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = findViewById(R.id.list_view); List<ImportViewModel> data = readExcelFile(); // 调用您的 readExcelFile() 方法获取数据 ImportViewModelAdapter adapter = new ImportViewModelAdapter(data); listView.setAdapter(adapter); TextView textView = findViewById(R.id.text_type); textView.setVisibility(View.GONE); TextView textView1 = findViewById(R.id.text_name); textView1.setVisibility(View.GONE); TextView textView2 = findViewById(R.id.text_style); textView2.setVisibility(View.GONE); TextView textView3 = findViewById(R.id.text_inventory_num); textView3.setVisibility(View.GONE); RfApplication.toneGenerator = new ToneGenerator(streamType, percantageVolume); btn_update = findViewById(R.id.btn_update); rvList = findViewById(R.id.list_view); rvList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { ShowData item = (ShowData) adapterView.getItemAtPosition(i); if (!isStarted) { modeDialog(item); } else { CustomToast.showLoad(MainActivity.this, getString(R.string.please_stop_read), 2000); } return true; } }); // showDataList = new ArrayList<>(); //adapter = new StockInListViewAdapter(this, showDataList); rvList.setAdapter(adapter); }java.lang.IllegalStateException: Cannot get a numeric value from a text cell怎么解决
这个错误通常是因为您在尝试从 Excel 表格中读取文本单元格时,将其转换为数字或其他类型时发生的。您可以通过在读取数据之前检查单元格类型并据此进行类型转换来解决此问题。以下是一个示例代码片段,演示如何处理这个问题:
```
private List<ImportViewModel> readExcelFile() {
List<ImportViewModel> data = new ArrayList<>();
try {
InputStream input = getAssets().open("data.xlsx");
Workbook workbook = WorkbookFactory.create(input);
Sheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
ImportViewModel item = new ImportViewModel();
Cell cell0 = row.getCell(0);
if (cell0.getCellType() == CellType.NUMERIC) {
item.setId((int) cell0.getNumericCellValue());
} else {
item.setId(Integer.parseInt(cell0.getStringCellValue()));
}
Cell cell1 = row.getCell(1);
item.setName(cell1.getStringCellValue());
Cell cell2 = row.getCell(2);
item.setStyle(cell2.getStringCellValue());
Cell cell3 = row.getCell(3);
if (cell3.getCellType() == CellType.NUMERIC) {
item.setInventoryNum((int) cell3.getNumericCellValue());
} else {
item.setInventoryNum(Integer.parseInt(cell3.getStringCellValue()));
}
data.add(item);
}
input.close();
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
```
这里的代码通过调用 `getCellType()` 方法检查单元格类型,并根据需要使用 `getNumericCellValue()` 或 `getStringCellValue()` 方法获取值。这应该能够解决您遇到的问题。
btn_fill_start.setOnClickListener(view->{ // 开始寻北指令 sendData("0x8080020103EE"); // 清空寻北的显示数据 northDataMsg = guideDataMsg = ""; showRecvData("", false); // 清空进度条 setProgressValue(0); progressValue = 0; progressFlag = false; }); btn_fill_stop.setOnClickListener(view->{ // 结束寻北指令 sendData("0x8080020204EE"); // 进度条停止 progressFlag = false; }); if(filterProduct){ // 隐藏三态开关 findViewById(R.id.filterBox).setVisibility(View.GONE); }else { // 三态开关设置 btn_switch_filter = findViewById(R.id.switch_filter); btn_switch_filter.setOnToggleChanged((toggleStatus, b, i) -> { switch (toggleStatus) { case mid: text_filter.setText(R.string.filter_name); break; case on: text_filter.setText(R.string.filter_pro); break; case off: default: text_filter.setText(R.string.filter_none); break; } }); text_filter = findViewById(R.id.text_filter); } text_recv_len = findViewById(R.id.text_recv_len); // 进度条 northProgress = findViewById(R.id.progressBar1); }解释每一句代码
这段代码是一个Android应用程序中某个Activity的部分代码,主要是对一些按钮和视图进行初始化和设置。具体来说:
- 第1个按钮(btn_fill_start)的点击事件监听器使用Lambda表达式定义,当点击该按钮时,会发送一个寻北指令给设备,并清空一些数据和显示。
- 第2个按钮(btn_fill_stop)的点击事件监听器使用Lambda表达式定义,当点击该按钮时,会发送一个结束寻北指令给设备,并停止进度条的更新。
- 如果filterProduct为真,则隐藏一个名为filterBox的视图;否则,初始化三态开关和用于显示当前状态的TextView。
- 初始化用于显示接收数据长度的TextView。
- 初始化一个名为northProgress的进度条视图。
请注意,这段代码缺少一些关键信息,例如sendData()方法的具体实现,因此无法完全理解该代码的功能。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)