Android ListView不显示该项目 [英] Android ListView Not displaying the item

查看:77
本文介绍了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 :-)


这篇关于Android ListView不显示该项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆