[英]How to associate event to a spinner selection
我已经为我的应用程序创建了一个微调器。 这是main.xml中的代码
<Spinner
android:id="@+id/sMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:prompt="@string/base"
/>
在我的主要班级
String [] base = {"Decimale", "Binaria", "Ottale", "Esadecimale"};
Spinner s1;
s1 = (Spinner) findViewById (R.id.sMenu);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.base, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
该程序将数字转换为二进制,十进制,八进制,十六进制。 我想将一些事件关联到微调器。 例如,如果选择微调器二进制文件,则在编辑文本中只能输入二进制数。 我可以通过哪种方式将此事件与微调器关联?
s1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id3) {
final String b = adapter.getItem(position);
// based on b you change the property inputType of your EditText
// for instance, if b is 'deciaml' you set as inputType 'numberDecimal'
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.