2014-01-13 94 views
0
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

做的怎麼樣,你做了'spnr'具有另一個適配器 – Raghunandan

+0

你是什麼意思,「如何申報另一個微調ID ...」?它看起來像你。你到底有什麼問題? – codeMagic

回答

0

每個微調有它的適配器綁定與視圖的數據源上的話,最有可能你需要爲每個微調,在任何其他數據視圖

0

的onCreate

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) { 

     } 

    }