我想一個適配器設置爲微調,但我不知道爲什麼我收到以下錯誤:錯誤創建ArrayAdapter
Cannot resolve constructor 'ArrayAdapter(com.example.app.DialogBox,int, java.util.list)'
這裏就是我嘗試填充微調並設置方法它的適配器:
public class DialogBox extends DialogFragment implements View.OnClickListener {
// To fill the age spinner
public ArrayAdapter<Integer> populateAgeSpinner() {
Log.d(TAG ,"populateAgeSpinner - Ini");
List age = new ArrayList<String>();
age.add("");
for(int i = 18; i <= 100; i++) {
age.add(Integer.toString(i));
}
ArrayAdapter<Integer> spinnerAgeAdapter = new ArrayAdapter<Integer>(this,R.layout.spinner_item_layout, age);
spinnerAgeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Log.d(TAG ,"populateAgeSpinner - Fi");
return spinnerAgeAdapter;
}
}
這是spinner_item_layout.xml
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_text"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="30dp"
android:ellipsize="marquee"
android:background="@color/com_facebook_button_send_background_color"
android:textColor="#000"
android:textAlignment="inherit"/>
您是否將適配器設置爲不擴展'Context'的類? – Onik
@Onik好吧,我的課是擴展DialogFragment我編輯我的問題我該如何解決這個問題? – rainman
[無法解析構造函數ArrayAdapter]可能的重複(http://stackoverflow.com/questions/28848735/cannot-resolve-constructor-arrayadapter) – Sufian