【发布时间】:2015-06-07 12:45:17
【问题描述】:
) 我再次需要你的帮助。 我尝试了 2 个小时来解决这个问题,我搜索了很多并寻找类似的问题。我找到了很多,但没有任何效果。
这是我的问题: 我从“植物”的 ArrayList 中填充一个微调器。 然后我为这个 Spinner 设置了一个适配器,最后是一个 OnItemSelectedListener。 当我打开活动时,微调器是空的。但他一定做了任何事情,因为当我返回主屏幕并再次打开应用程序(通过图标,而不是任务管理器)时,微调器已正确填充。 我不能只是重新加载活动,因为然后我陷入了无限循环:( 我认为 Spinner 在使用 OnStart 方法后会重新加载。但是我现在不知道该怎么做:(
这是我的代码:
*public class entscheidungsbaum extends Activity implements OnItemSelectedListener {
private Spinner spAlter= null;
private Spinner spArt= null;
private Spinner spBlaetterrand= null;
private Spinner spBlaetterForm= null;
private Spinner spBlueten= null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.entscheidungsbaum);
final Activity activity = this;
activity.setTitle("Pflanze eintragen");
spAlter = (Spinner)this.findViewById(R.id.spAlter);
spArt = (Spinner)this.findViewById(R.id.spArt);
spBlaetterrand = (Spinner)this.findViewById(R.id.spBlaetterrand);
spBlaetterForm = (Spinner)this.findViewById(R.id.spBlaetterform);
spBlueten = (Spinner)this.findViewById(R.id.spBlueten);
FillSpinner();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
public void onButtonClick (View Click) {
switch(Click.getId()){
default: return;
case R.id.weiter:
startActivity(new Intent(this, formular.class));
return;
}
}
public void FillSpinner(){
Bundle extras = getIntent().getBundleExtra("plantbundle");
ArrayList<Plant> plantlist = extras.getParcelableArrayList("plant");
ArrayAdapter<Plant> spinnerArrayAdapter = new ArrayAdapter<Plant>(this, android.R.layout.simple_spinner_item,plantlist);
spAlter.setAdapter(spinnerArrayAdapter);
spAlter.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
Plant plant = (Plant)spAlter.getSelectedItem();
// Anzeigen
toast_selec_plant(plant);
}
private void toast_selec_plant(Plant plant) {
Toast.makeText(this, "Pflanze ausgewählt:" + plant.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}*
伊迪丝发现: 我从意图中得到的植物列表是空的,这就是为什么旋转器也保持空的原因。 但是当我退出应用程序并再次进入时,它可以工作。奇怪的。如果您有任何提示,欢迎您;)
【问题讨论】: