java - java - 如何根据来自editText的输入和Java中的微调器中的选定项目创建表格?
问题描述
我希望这些值显示在有组织的表格中。到目前为止,我只能将来自 spinner 的选定项目和来自 editText 的值显示为按行填充的文本。这是我的代码:
final TextInputEditText input = findViewById(R.id.editInput);
final TextView text = (TextView) findViewById(R.id.selectedCrop);
text.setText(" ");
final Spinner cropsSpinner = (Spinner) findViewById(R.id.spinnerCrop);
cropsAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, crops);
cropsSpinner.setAdapter(cropsAdapter);
final String editInput = input.getText().toString();
cropsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final String editInput = input.getText().toString();
if (!editInput.isEmpty()) {
final String crop = crops[position];
text.setText(text2 + crop + " " + editInput + "\n");
text2 = text.getText().toString();
}
}
我怎样才能让它出现在表格中?
解决方案
好吧,我找到了我的问题的答案。解决方案是通过从 EditText 获取输入和从 spinner 获取 selectedItem 以编程方式使用 TableLayout 并使用 TableRows 填充 TableLayout
推荐阅读
- sql - 如果前两列的答案匹配,则创建一个返回“是”的列
- javascript - 如何移动我的 h3 元素以与 span 元素垂直对齐?
- java - 使用 Tabula 使用 Python 读取 pdf 时出现 Java 错误
- f# - FSharp.Data JsonProvider 的重命名类型
- asp.net-mvc - 事件驱动架构数据库处理
- python - 如何使用 Python 的 ast 创建类型化的返回?- `def f() -> bool: return True`
- javascript - 在没有 @oninput 的情况下获取 Blazor 中输入字段的值
- c# - 如何使用 FiddlerCore 将 https 隧道流量重定向到 https://localhost:8444
- php - 隐藏的令牌字段不是不安全的吗?
- python - 将 Spark DataFrame 中具有多个时区的所有时间戳标准化为 UTC 格式