如何在android中添加List到Array List?

时间:2015-03-26 13:55:13

标签: java android telephony telephonymanager

我正在使用getNeighboringCellInfo()获取TelephonyManager。我希望在列表视图中列出相邻广告的详细信息。我成功获取了相邻的广告但我无法显示在列表视图中请帮我解决这个问题。

listedSignals = (ListView)findViewById(R.id.listSignals);

private void getNeighbors(TelephonyManager telephonyManager) throws InterruptedException {
   List<NeighboringCellInfo> neighboringCellInfos;
   neighboringCellInfos = telephonyManager.getNeighboringCellInfo();
   neighboringCellBlockingQueue = new LinkedBlockingQueue<>(100);
   for (int i = 0;i < neighboringCellInfos.size();i++) {
       NeighboringCellInfo info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
       ArrayList<NeighboringCellInfo> cellInfoList = new ArrayList<>(neighboringCellBlockingQueue.size() + 1);
       while (info != null) {
           cellInfoList.add(info);
           info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS);
       }
       neighboringCellInfos = cellInfoList;
   }
}

neighboringCellInfos包含所有相邻单元格的详细信息。所以请在neighboringCellInfos列表视图中使用listedSignals告诉我。

1 个答案:

答案 0 :(得分:1)

您需要创建一个adapter特定于您要在ListView中显示的信息(此处已有many examples of this)。使用您自己的自定义适配器,您可以定义要在ListView中显示的信息。完成后,您只需将列表添加到适配器,并在活动中设置adapter的{​​{1}},如下所示:

ListView