public class StartCalvert extends Activity {
Spinner spnr,spnr2;
String[] numsys = {
"Binary",
"Decimal",
"Octal",
"Hexadecimal"
};
// this numsys how will i declare
String[] numsys2 = {
"Binary",
"Decimal",
"Octal",
"Hexadecimal"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startcalvert);
spnr2 = (Spinner)findViewById(R.id.spinner2);
spnr = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, numsys);
//declare here , like what above alike .
spnr.setAdapter(adapter);
spnr.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener()
答案 0 :(得分:0)
每个Spinner都有它的适配器将其Datasource与视图绑定在一起,所以很可能你需要为每个Spinner和任何其他数据视图创建一个
答案 1 :(得分:0)
spinner1 = (Spinner) findViewById(R.id.spinner1 );
spinner2 = (Spinner) findViewById(R.id.spinner2 );
ArrayAdapter<String> adapterSpinner1 = new ArrayAdapter<String>(
SpinnerActivity.this, R.layout.simple_spinner_item,
numsys);
spinner1.setDropDownViewResource(R.layout.simple_spinner_item);
spinner1.setAdapter(adapterSpinner1);
ArrayAdapter<String> adapterSpinner2 = new ArrayAdapter<String>(
SpinnerActivity.this, R.layout.simple_spinner_item,
numsys2);
spinner2.setDropDownViewResource(R.layout.simple_spinner_item);
spinner2.setAdapter(adapterSpinner2);
ItemSelectedListener itemSelectedListener = new ItemSelectedListener();
spinner1.setOnItemSelectedListener(itemSelectedListener);
spinner2.setOnItemSelectedListener(itemSelectedListener);
声明内部类
class ItemSelectedListener implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position,
long arg3) {
LoggerGeneral.info("OnItemselected pressed");
switch (parent.getId()) {
case R.id.spinner1:
break;
case R.id.spinner2:
break;
default:
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}