2013-06-26 6 views
0

리스트 pref와의 작업에 문제가 있습니다. 나는 ... 문리스트 Pref trouble android

내가 그래서 코드를 게시 할 것 나던 메이크업 감각을 내기 경우와 다른 값 목록 현 값과 일치하는 것을 시도하고있다

stripedMain :

String stripeType = ""; 
void drawStriped() { 
      final SurfaceHolder holder = getSurfaceHolder(); 
      Canvas c = null; 
      try { 
       c = holder.lockCanvas(); 
       if (c != null) { 
        if (stripeType == "vert") 
        { 
        android.util.Log.d("stripedLog", "working");  
         } 
       } 
      } finally { 
       if (c != null) 
        holder.unlockCanvasAndPost(c); 
      } 
............. 

Settings.XML의 :

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > 

    <PreferenceCategory 
     android:key="firKey" 
     android:title="Wallpaper Settings" > 

     <ListPreference 
      android:defaultValue="hor" 
      android:entries="@array/stripe_entries" 
      android:entryValues="@array/stripe_values" 
      android:key="stripe_type" 
      android:title="Type" /> 

    </PreferenceCategory> 

</PreferenceScreen> 

shapes.xml :

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> 

    <string-array name="stripe_entries"> 
     <item>"Horizontal"</item> 
     <item>"Vertical"</item> 
     <item>"Both"</item> 
      <item>"Both+CrossOver"</item> 
    </string-array> 

    <string-array name="stripe_values"> 
     <item>"hor"</item> 
     <item>"vert"</item> 
     <item>"both"</item> 
     <item>"bothOver"</item> 
    </string-array> 

</resources> 
,

....이 작동하지 않습니다와 나는 아무 생각이 왜

답변

0

유는

그래서 당신은 무엇을해야 페치 문자열과 비교하기 위해 기본 공유 설정을 가져 havent 한 사촌 그것은 작동하지 않습니다 그것을 다음과 같이 비교하십시오 :

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 

    String stripeType = prefs.getString("stripe_type", "stripe_type") 


    void drawStriped() { 
       final SurfaceHolder holder = getSurfaceHolder(); 
       Canvas c = null; 
       try { 
        c = holder.lockCanvas(); 
        if (c != null) { 
         if (stripeType.equalsIgnoreCase("vert")) 
         { 
         android.util.Log.d("stripedLog", "working");  
          } 
        } 
       } finally { 
        if (c != null) 
         holder.unlockCanvasAndPost(c); 
       } 
+0

감사합니다. 귀하의 답변은 정확히 알려지지 않았지만 문제를 해결하는 데 도움이되었습니다. 문제는 내가 이것을하지 못한다는 것이었다. if (stripeType.equalsIgnoreCase ("vert")) –

+0

이제 코드가 작동하기 시작 했는가? –