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);
}
}
瞭解如何使用自定義適配器。 – 2015-01-20 20:49:51