使用硬编码数据将 EditText 更改为 Spinner
Change EditText to Spinner with hardcoded data
在下面的代码中,用户可以键入所需的类别并保存以进行解析table。我想避免用户输入错别字,并希望使用带有硬编码类别的 Spinner,用户可以从下拉菜单中 select。但是我无法创建微调器,因为我以前没有使用微调器小部件的经验。任何人都可以提供如何实现这一目标的示例吗?这是我当前的代码。
event.put("category", mEditCategory.getEditText().getText().toString()); // mEditCategory.getSpinner?????
String strCat = mEditCategory.getEditText().getText().toString();
if (TextUtils.isEmpty(strCat))
{
mEditCategory.setError("Especifique una categoria: trafico/chismes");
return;
}
感谢您抽出宝贵时间。
我建议看一下 this example and explanation by mkyong。它非常详尽,您应该能够轻松跟进。要回答有关对选项进行硬编码的主要问题:正如您将在示例中看到的那样,您将使用代码将加载的 strings.xml 文件中指定的列表。
在下面的代码中,用户可以键入所需的类别并保存以进行解析table。我想避免用户输入错别字,并希望使用带有硬编码类别的 Spinner,用户可以从下拉菜单中 select。但是我无法创建微调器,因为我以前没有使用微调器小部件的经验。任何人都可以提供如何实现这一目标的示例吗?这是我当前的代码。
event.put("category", mEditCategory.getEditText().getText().toString()); // mEditCategory.getSpinner?????
String strCat = mEditCategory.getEditText().getText().toString();
if (TextUtils.isEmpty(strCat))
{
mEditCategory.setError("Especifique una categoria: trafico/chismes");
return;
}
感谢您抽出宝贵时间。
我建议看一下 this example and explanation by mkyong。它非常详尽,您应该能够轻松跟进。要回答有关对选项进行硬编码的主要问题:正如您将在示例中看到的那样,您将使用代码将加载的 strings.xml 文件中指定的列表。