android - Android Spinner with different Value
问题描述
I created a spinner in my xml with the options permanent
and temp
and when the user clicks on it, it has to add to my azure database, the only problem i am facing is that if the user clicks permanent
it must add a 1
to my database and if the user clicks temp
it must add a 0
to my database
Here is my strings.xml
<string-array name="customerstatus">
<item>permanent</item>
<item>temporary</item>
</string-array>
解决方案
您可以使用
spinner.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
String selectedItem = parent.getItemAtPosition(position).toString();
if(selectedItem.equalsIgnoreCase("permanent")) {
// Value should be 1
} else if(selectedItem.equalsIgnoreCase("temp")) {
// Value should be 0
}
} // to close the onItemSelected
public void onNothingSelected(AdapterView<?> parent)
{
}
});
您还可以通过代码在微调器中添加动态值,如此处所述
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_item, new String [] {"USA", "Europe"});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
推荐阅读
- c# - 从表达式函数获取属性
- react-native - 如何将屏幕过渡指定为水平滑动
- angular - 工具提示内的条件运算符不起作用
- ios - 如何在 iOS 应用程序中使用标准经典蓝牙配置文件?
- javascript - 类型错误,无法读取未定义的属性 0
- google-apps-script - 由 Chrome V8 提供支持的新应用程序脚本运行时缺少执行记录
- excel - 电子邮件宏问题正文
- java - 在 Tomcat 上部署的 Spring Boot 2 应用程序上找不到/读取 Bootstrap.yml
- python - 在 Jupyter Notebook 中获取 shell 命令的输出
- jsonschema - 是否可以从数据库配置生成 JSONSchema?