2015-01-20 54 views
0

我的微調器接收來自strings.xml的數據,但我想更改接收數據以從對象中獲取數據的方式。我有班級和名字。我想在微調器中顯示名稱。你可以幫我嗎?我的課,對象和微調的代碼:Android如何更改微調陣列中接收到的數據從對象中接收

public class DruzynyStatActivity extends ActionBarActivity { 
    public class Team { 
     public String name; 
     public String shoots; 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_druzyny_stat); 
     getSupportActionBar().hide(); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_druzyny_stat, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 


    public void cracovia(View view) { 
     Intent intent = new Intent(this, CracoviaActivity.class); 
     Team cracovia = new Team(); 
     cracovia.name = "Cracovia"; 
     String name = cracovia.name; 
     intent.putExtra("teamName", name); 
     cracovia.shoots = "STRZAŁY: 10"; 
     String shoots = cracovia.shoots; 
     intent.putExtra("shoots", shoots); 
     startActivity(intent); 

    } 
} 

和紗廠代碼:

public class PorownanieActivity extends Activity implements AdapterView.OnItemSelectedListener { 
    Spinner spinner1; 
    Spinner spinner; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_porownanie); 
     spinner1 = (Spinner) findViewById(R.id.spinner); 
     ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.ZESPOŁY, android.R.layout.simple_list_item_1); 
     spinner1.setAdapter(adapter); 
     spinner1.setOnItemSelectedListener(this); 
     spinner = (Spinner) findViewById(R.id.spinner1); 
     ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this, R.array.ZESPOŁY, android.R.layout.simple_list_item_1); 
     spinner.setAdapter(adapter1); 
     spinner.setOnItemSelectedListener(this); 


    } 
} 
+0

瞭解如何使用自定義適配器。 – 2015-01-20 20:49:51

回答

0

您可以從對象創建ArrayAdapter並將其設置爲微調。 您應該對適配器構造一看,你可以像這 -

 String list[] = new String[]{"string1","string2"}; 
    ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, 
       android.R.layout.simple_dropdown_item_1line,list); 
    spinner.setAdapter(adapter); 

您可以從任何類型對象的創建適配器寫,你應該對構造函數適配器看看。 有關更多自定義和對象列表,還可以擴展BaseAapter和ArrayAdapter類。

相關問題