首页 > 解决方案 > 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();
              }

        }

我怎样才能让它出现在表格中?

标签: javaandroid

解决方案


好吧,我找到了我的问题的答案。解决方案是通过从 EditText 获取输入和从 spinner 获取 selectedItem 以编程方式使用 TableLayout 并使用 TableRows 填充 TableLayout


推荐阅读