我为我的应用程序创建了一个微调器。这是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);
程序转换二进制,十进制,八进制,十六进制数。我想将一些事件与微调器相关联。例如,如果我在微调器二进制文件中选择,则在编辑文本中我只能放入二进制数字。我可以通过哪种方式将此事件与微调器相关联?
答案 0 :(得分:1)
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) {
}
});