2014-05-11 189 views
-3

我已經開發了周圍的掃描我的設備現有的WiFi信號,並顯示他們的名字和他們的實力以及如下應用:如何將一個掃描列表分配給一個變量?

tv = (TextView) findViewById (R.id.textView1); 

List <ScanResult> results = wm.getScanResults(); 

String otherwifi="The existing network is:\n\n"; 
System.out.println(result.SSID.toString());  
System.out.println(result.level); 
for (ScanResult result: results) { 
    otherwifi+=result.SSID+":"+result.level+"\n"; 
    tv.setText (otherwifi); 
} 

,這是的System.out.println:

>05-11 10:08:30.860: I/System.out(27621): rubelwifii 
>05-11 10:08:30.860: I/System.out(27621): -50 
>05-11 10:08:30.860: I/System.out(27621): aliwifi 
>05-11 10:08:30.860: I/System.out(27621): -92 
>05-11 10:08:30.860: I/System.out(27621): ABDULHAKEEM 
>05-11 10:08:30.860: I/System.out(27621): -55 
>05-11 10:08:30.860: I/System.out(27621): shamwifi 
>05-11 10:08:30.860: I/System.out(27621): -70 
>05-11 10:08:30.860: I/System.out(27621): Fuselage 
>05-11 10:08:30.860: I/System.out(27621): -84 

現在我想預定義它們中的每一個作爲變量來使用它們進行進一步處理?

+0

你是問如何將結果存儲在一個變量列表? –

+0

我問如何給他們一個定義的名稱在Eclipse例如 名1 = rubelwifii strength1 = -50 名稱2 = ABDULHAKEEM 強度2 = -55 等 希望你明白我的意思,並幫我一下吧 – user3610902

回答

0

聽起來像是你想是這樣的:

// pre-defined names and strengths... 
String name1 = "rubelwifii"; 
int strength1 = -50; 
String name2 = "aliwifi"; 
int strength2 = -92; 
String name3 = "ABDULHAKEEM"; 
int strength3 = -55; 
String name4 = "shamwifi"; 
int strength4 = -70; 
String name5 = "Fuselage"; 
int strength5 = -84; 

// a hashmap to store your results 
HashMap<String, ScanResult> hashMap = new HashMap<String, ScanResult>(); 

tv = (TextView) findViewById (R.id.textView1); 

List <ScanResult> results = wm.getScanResults(); 

String otherwifi="The existing network is:\n\n"; 
System.out.println(result.SSID.toString());  
System.out.println(result.level); 
for (ScanResult result: results) { 
    // store the result in a hashmap so you can get at it later 
    hashMap.put(result.SSID.toString(), result); 

    otherwifi+=result.SSID+":"+result.level+"\n"; 
    tv.setText (otherwifi); 
} 

// do something with the first and second result 
ScanResult result1 = hashMap.get(name1); 
ScanResult result2 = hashMap.get(name2); 

// compare strength of #1 to the predefined value... (I'm assuming int is the data type) 
if (result1.level == strength1) { 
    // do something 
} 

// do same for #2 
if (result2.level == strength2) { 
    // do something... 
} 
+0

感謝您的反饋 但強度值不是恆定的......他們隨着設備的移動而變化,所以我想要獲得來自掃描過程的強度結果,然後使用它們 希望是得到我的觀點 你想切換到聊天更好的解釋我真的很感激,因爲我真的需要幫助plz @Ryan j – user3610902

0
HashMap hm = new HashMap(); 
// String key; 
for (ScanResult result: results) { 

    // key = cleanYourVarname(result.wifiName); 
    // hm.put(key, result); 

    /* key should be a clean string I assume wifi name as result.SSID */ 
    hm.put(result.SSID.toString(), result); 

} 
// retrieve 
hm.get("rubelwifii"); 
+0

它沒有工作bro – user3610902

+0

試試這個 hm.put(result.SSID.toString(),result); – kazimt9

+0

兄我試圖用另一種方法,但我仍然有問題,也許你可以幫助我,我jsust在這裏發佈了一個問題,在這裏解釋它 你可以檢查它形式和幫助我這是鏈接 http:// stackoverflow。 com/questions/23590743/if-statment-in-eclipse 或者您想切換到聊天嗎? 我真的很感謝你的幫助 – user3610902

相關問題