Android ListView不显示该项目

Android ListView不显示该项目

问题描述:

以下代码显示附加Deveice列表,但它没有显示设备。

Following Code Display attached Deveice in List,But it not showing the Devices.

Showing Message Exception : null;
	@Override
	protected void onNewIntent(Intent intent) {
		try
		{
			UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
			HashMap<string,> deviceList = manager.getDeviceList();
			Iterator<usbdevice> deviceIterator = deviceList.values()
					.iterator();
			while (deviceIterator.hasNext()) {
				UsbDevice device = deviceIterator.next();
				if(device==null)
					return ;
				String deviceName = device.getDeviceName();
				listDeviceName.add(deviceName);
			}

			/*runOnUiThread(new Runnable()
			{
				@Override
				public void run() {*/
					
					final ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1, listDeviceName);
					listview.setAdapter(adapter);
			/*	}
			});*/
		}
		catch(Exception e)
		{
			Toast.makeText(this,"Exception :"+e.getMessage(),Toast.LENGTH_SHORT).show();
		}
	}

}

if(device==null)
    return ;



错了。你不应该在这一点上返回,而是使用 continue 重复循环,直到 hasNext 返回 false 。然后你将退出循环并显示列表视图。


is wrong. You should not return at this point but use continue to repeat the while loop, until hasNext returns false. You will then fall out of the loop and display the listview.


快速浏览一下我会说



Quick glance and I would say

if(device==null)
   return ;





需要





Needs to be

if(device==null)
   continue ;





/ Darren



编辑:发布时没有答案,所以我不知道发生了什么,但至少我得到了同样的答案是正确的: - )



/Darren

When posted no answer was on this so I don't know what happened but at least I got the same answer correct :-)