Spinner不会填充并且不会设置arrayadapter

时间:2014-05-23 14:44:00

标签: android eclipse spinner android-arrayadapter

我的应用程序通过点击按钮将主屏幕重定向到城市屏幕。我走到城市的屏幕后。我试图填充一个微调器(id = countries)。但是,当我运行它时,它会在我的城市课堂中打开一个空的旋转器。

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_city);

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
        .add(R.id.container, new PlaceholderFragment()).commit();
    }


}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{

    View v = inflater.inflate(R.layout.fragment_city, container, false);

    String[] test = {"test1", "test2"};
    Spinner spin = (Spinner) v.findViewById(R.id.countries);
    ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, test);
    adapt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(adapt);

    return v;
}

0 个答案:

没有答案