我有以下显示我的问题的最小程序(android 2.2(API 8)):如果我从 onCreate() 调用 start()-Method 一切正常,但如果我从 onWindowFocusChanged() 调用它我不是能够从微调器中选择一个项目。有谁能够帮我?
package de.thomasklein1982;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class SpinnerExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//call start() from here and everything is just fine
//start();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//call start() from here and it's impossible to select a spinner-item
start();
}
public void start(){
Spinner spinner=new Spinner(this);
List<String> list = new ArrayList<String>();
list.add("Item 1");
list.add("Item 2");
list.add("Item 3");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getBaseContext(),
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
setContentView(spinner);
}
}