2013-05-02 50 views
2

我創建了一個Android百家樂遊戲。我有六張總牌,每個玩家顯示三張牌。之前我使用的應用程序,每張卡都顯示正確,現在玩家第二張和第三張牌已經切換位置,我沒有改變我的代碼中的任何東西。錯誤的ImageView正在更新

<ImageView 
     android:id="@+id/PlayerCard2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/PlayerCardsTotalText" 
     android:layout_alignLeft="@+id/TieBetTotalText" 
     android:layout_alignParentBottom="false" 
     android:contentDescription="@string/PlayerCard2Image" 
     android:src="@drawable/b1fv" /> 

    <ImageView 
     android:id="@+id/PlayerCard3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/PlayerCardsTotalText" 
     android:layout_alignParentRight="true" 
     android:contentDescription="@string/PlayerCard3Image" 
     android:src="@drawable/b1fv" /> 

這是玩家卡的XML代碼。 PlayerCard2 & PlayerCard3是已經轉換的玩家。

PlayerCardImage2.setImageResource(deckOfCards[PlayerCard+ generateSuit()]); 

這是根據數組中隨機選擇的數字更新圖像的java代碼。

我已經嘗試切換卡的位置,我仍然得到相同的結果。

PlayerCardImage1 = (ImageView)findViewById(R.id.PlayerCard1); 
    PlayerCardImage2 = (ImageView)findViewById(R.id.PlayerCard2); 
    PlayerCardImage3 = (ImageView)findViewById(R.id.PlayerCard3); 

這是我參考活動中的圖像的地方。

+0

請問您可以在哪裏得到'PlayerCardImage2'變量的代碼? – 2013-05-02 06:47:29

+1

我們只能建議確保'PlayerCardImage2'引用正確的'ImageView'。仔細檢查你的'findViewById(R.id.PlayerCardxxxxx)'語句。否則發佈你的所有'onCreate()'代碼 – 2013-05-02 06:47:46

回答

1

聽起來像自動生成的R類被搞砸了,這偶爾會發生。 你應該清理你的項目 - 在Eclipse中:項目 - >清理... - >檢查你的項目。這也將觸發R的娛樂,並應解決您的問題。

+0

謝謝。這解決了我從未見過的問題。爲什麼會發生這種情況的具體原因? – 2013-05-02 06:56:00