2014-05-11 154 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

相关问题