【问题标题】:Why the tag statement is getting displayed multiple times for my Log为什么我的日志中多次显示标记语句
【发布时间】:2018-05-23 06:35:58
【问题描述】:

我正在为单击侦听器使用日志语句以在数组列表中显示字符串。根据官方文档,Log.i(tag, message) 中的“tag”参数用于识别日志消息的来源。它通常标识发生日志调用的类或活动。下面是记录数组列表字符串的代码。

for (int i = 0; i < Response.size(); i++){
      Log.i("Resulted String", Response.get(i));
  }

在logcat中,arraylist中的字符串已经显示出来了。但是,对于第一个运行标记语句,会显示在所有字符串之前。第二次运行,标签显示 2/3 次,依此类推。下面是我第一次运行代码时得到的输出。

结果字符串: StatusOK
金额2500.00score983
CAR25.00score773
LAR2200.00score780
Codeline.125000024._81922_767,_1127score993
收款人姓名Gscore23
日期May5,2018score925
CheckNumber1127score1000

标签在下次运行时显示如下。

结果字符串: StatusOK
金额2500.00score983
CAR25.00score773
LAR2200.00score780
Codeline.125000024._81922_767,_1127score993
PayeeNameGscore23
结果字符串: DateMay5,2018score925
CheckNumber1127score1000
结果字符串: StatusOK
金额2500.00score983
CAR25.00score773
结果字符串: LAR2200.00score780
Codeline.125000024._81922_767,_1127score993
收款人姓名Gscore23
日期May5,2018score925
CheckNumber1127score1000

我的问题是为什么这个标签语句没有与每个字符串一起显示,为什么只显示几个字符串以及在什么基础上显示。

请有人澄清一下。

谢谢

【问题讨论】:

  • 在循环后连接到StringBuffer然后log
  • 请分享getSplittedResult代码。
  • 打印Response.size以验证列表大小

标签: java android arraylist android-log


【解决方案1】:

您可以按如下方式使用StringBuilder 来实现您的预​​期输出:

StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < Response.size(); i++){
     stringBuilder.append(Response.get(i));
}
Log.i("Resulted String", stringBuilder.toString());

【讨论】:

  • 我需要得到查询中提到的分隔字符串的结果,所以我使用了 arraylist 。有了这个解决方案,我可以生成一个应该再次更改为 Arraylist 的单个字符串。
  • @jellybean And with this solution i can generate a single string which i should be changed to Arraylist&lt;Strings&gt; again 你是什么意思?你的意思是你想保持字符串分开并在不同的行打印?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-19
  • 1970-01-01
  • 2017-03-11
  • 2013-12-17
  • 2012-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多