2014-12-04 64 views
0

我對-1在以下arraylist中表示什麼感到困惑。請有人幫助我,謝謝。在java/android中使用arraylist

toyList.add(new toyStore(toyName[0], toyIcon.getResourceId(0, -1))); 
toyList.add(new toyStore(toyName[1], toyIcon.getResourceId(1, -1))); 

回答

0
getResourceId (int index, int defValue) 

它是利用DefValue爲代表的值,如果屬性沒有定義或不是資源返回。

更多的解釋:

公衆詮釋getResourceId(INT指數,整數利用DefValue)

在API級別1檢索在索引 屬性的資源標識符。請注意,當檢索到整體TypedArray對象時,屬性資源已解析。因此,此功能 將返回發現 的最終資源值的資源標識符,而不一定是 屬性指定的原始資源。

參數索引要檢索的屬性索引。 defValue值爲 如果屬性未定義或不是資源,則返回。返回 屬性資源標識符,如果未定義,則返回defValue。

0

getResourceId(0, -1)toyIcon的索引0處給出資源ID,或者如果該屬性未定義或不是資源,則它將返回-1。
在文檔

public int getResourceId (int index, int defValue) 
Parameters 
index Index of attribute to retrieve. 
defValue Value to return if the attribute is not defined or not a resource. 
Returns 
Attribute resource identifier, or defValue if not defined. 

參見此:http://developer.android.com/reference/android/content/res/TypedArray.html#getResourceId(int,INT)
同樣toyIcon.getResourceId(1, -1)將以toyIcon索引1返回資源Id或-1,如果該屬性沒有定義或不是資源。