Im在我的微調器上創建ArrayAdapter時遇到麻煩。我不知道如何向大家解釋,但人們說一張圖片可以說1000字。所以我提供了我的問題的照片。請幫助我,我真的不知道該怎麼做才知道。ArrayAdapter中的createFromResources()不能應用於微調器
這是我的課
public class SettingFragment extends Fragment{
private View rootView;
Spinner spinner;
ArrayAdapter<CharSequence> adapter;
public SettingFragment(){
//required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_setting, container, false);
spinner = (Spinner)rootView.findViewById(R.id.spinner);
adapter = ArrayAdapter.createFromResource(this, R.array.select_font_size, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
return rootView;
}
}
這是我string.xml
<string-array name="select_font_size">
<item>Small</item>
<item>Default</item>
<item>Large</item>
<item>Larger</item>
</string-array>
,這是我的XML代碼
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_gravity="center_horizontal" />
謝謝!它的工作! – HesZrave