2013-08-24 49 views
0

我有三個微調器,兩個從代碼填充,第三個來自XML arrays.xml。第三個不顯示任何標籤,只是每個項目的空行。在xml中填充的微調器顯示爲空(Android)

我在logcat中得到的錯誤:

W /的ResourceType(22121):失敗得到在包0 0x010802c8(T = 7 E = 712)記錄(故障-75)

但我不「知道這一行做什麼......我的XML充滿紗廠早期和他們沒關係,我不知道我做錯了什麼......

我的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <TextView 
     android:id="@+id/text_from" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/text_from" /> 

    <Spinner 
     android:id="@+id/spinner_start" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/text_from" /> 

    <TextView 
     android:id="@+id/text_length" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/text_length" 
     android:layout_below="@id/spinner_start" /> 

    <Spinner 
     android:id="@+id/spinner_length" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:entries="@array/length_value" 
     android:entryValues="@array/length_value" 
     android:defaultValue="10" 
     android:layout_below="@id/text_length" /> 

    <CheckBox 
     android:id="@+id/check_from_lesson" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/check_from_lesson" 
     android:layout_below="@id/spinner_length" /> 

    <Spinner 
     android:id="@+id/spinner_lesson" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/check_from_lesson" /> 

    <Button 
     android:id="@+id/button_select_from_list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_select" 
     android:layout_below="@id/spinner_lesson" /> 

    <Button 
     android:id="@+id/button_ok" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_ok" 
     android:layout_below="@id/spinner_lesson" 
     android:layout_toRightOf="@id/button_select_from_list" 
     android:onClick="onOkButtonPress" /> 


</RelativeLayout> 

我的arrays.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <array name="length_value"> 
     <item>5</item> 
     <item>10</item> 
     <item>15</item> 
     <item>20</item> 
     <item>25</item> 
    </array> 
</resources> 

我的代碼調用的佈局和填充等2個紡紗:

public void setTestParams() { 

     setContentView(R.layout.main_popup_layout); 
     sp_lesson = (Spinner)findViewById(R.id.spinner_lesson);  
     Spinner sp_start = (Spinner)findViewById(R.id.spinner_start); 
     sp_lesson.setEnabled(false); 

     List<String> lessons = new ArrayList<String>(); 
     List<String> start = new ArrayList<String>(); 
     lessons=getLessons(); 
     start=getStart(); 

     ArrayAdapter<String> spAdapterStart = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, start); 
     ArrayAdapter<String> spAdapterLessons = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, lessons); 

     spAdapterStart.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spAdapterLessons.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     sp_start.setAdapter(spAdapterStart); 
     sp_lesson.setAdapter(spAdapterLessons); 


     spAdapterLessons.notifyDataSetChanged(); 
     spAdapterStart.notifyDataSetChanged(); 

     final CheckBox cb_lesson = (CheckBox)findViewById(R.id.check_from_lesson); 
     cb_lesson.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       if(cb_lesson.isChecked()){ 
        sp_lesson.setEnabled(true); 
       }else{ 
        sp_lesson.setEnabled(false); 
       } 
      } 
     }); 


    } 

回答

0

試試這個:

<string-array name="length_value"> 
     <item>5</item> 
     <item>10</item> 
     <item>15</item> 
     <item>20</item> 
     <item>25</item> 
    </string-array> 
+0

它看起來不錯,標籤現在可見,但每次點擊微調器時我仍然在logcat中收到警告消息。 – Schipe

0

試試這個,

Resources res = getResources(); 
apModeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, res.getStringArray(R.array.anti_pump_ap_mode_array)); 
+0

我不想處理它的代碼,但感謝,這是一個好主意爲好。 – Schipe

1

的SPINN呃在你從資源讓你的數據,但不能發現它

就應該添加:

android:entries="@array/length_value" 

微調在XML文件中...

,也與改變:

<string-array name="length_value"> 
    <item>5</item> 
    <item>10</item> 
    <item>15</item> 
    <item>20</item> 
    <item>25</item> 
</string-array> 
+0

微調框已經有了這一行。我在arrays.xml中將數組替換爲字符串數組,並且它顯示正確,但我仍然有錯誤消息。 – Schipe