Setting up Spinner filled with data without any reference to Android resources

馋奶兔 提交于 2019-12-13 08:07:01

问题


Busy creating an interface with spinner (dropdown) programmatically. To populate with data you need an (Array)Adapter. What I don't understand is why you need a reference to an Android resource at all, like "android.R.layout.simple_spinner_dropdown_item". Is it possible to populate the Spinner with webservice data, without any reference to such an Android resource? If not, why not and how should this resource look like, in an environment without layout's. If it is possible, please show me how, since google is no help here (to me).

Thanks in advance!

Update:

Spinner spinner = new Spinner(this.getActivity());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), whatComesHere, list);
spinner.setAdapter(dataAdapter);
tableRow.addView(spinner);

The questions is: what to substitute for 'whatComesHere'?

thanks in advance.

Update-2

<Spinner
    android:id="@+id/spinner_admin_platform"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:entries="@array/my_spinner" />

回答1:


Here is an example:

 private void FillCitySnipper() {
ArrayList<MyCity> ListOfCity=db.LoadMyCity();
            // TODO Auto-generated method stub
            if (ListOfCity.size() > 0) {
                Spinner spinner = (Spinner) this
                        .findViewById(R.id.spnr_Cityname);
                ArrayAdapter<MyCity> spinnerArrayAdapter = new ArrayAdapter<MyCity>(
                        this,
                        android.R.layout.simple_spinner_dropdown_item,
                        ListOfCity);
                spinner.setAdapter(spinnerArrayAdapter);
            }
    }


来源:https://stackoverflow.com/questions/21759117/setting-up-spinner-filled-with-data-without-any-reference-to-android-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!