1
我有一個客戶端類中的方法收集來自服務器的數據,並返回一個HashMap。我想在Android對話框中列出鍵。 android API要求數據必須以CharSequence []的形式存在。據我所知,沒有直接的方法來轉換這些數據類型。什麼是實現這一目標的最佳方式?將HashMap.keySet()轉換爲CharSequence []?
下面是聲明和HashMap的初始化和鍵集:
Map <String, String> players = client.listPlayers();
Set<String> player_names = players.keySet();
And here is the link to the android Dialog documentation.
注:的CharSequence,它能夠從一組鑄造是不一樣的CharSequence [ ]
任何幫助表示讚賞。
-Sean W.
爲什麼CharSequence的[0],而不是爲CharSequence [players.keySet()大小()]? – 2010-11-12 03:20:34
雖然我會使用'新的CharSequence [players.size()]'。 – ColinD 2010-11-12 03:20:52
@Sean:使用長度爲0的數組可以很好地工作,對'toArray'來說是完全合法的,但是要自己製作正確大小的數組稍微好一些。 – ColinD 2010-11-12 03:23:18