【发布时间】:2020-06-03 18:11:32
【问题描述】:
我有一个不知道如何克服的小挑战。 从 Firebase 数据库中,我收集了一些数据,我想在“textview”中打印出来。
我有流动的函数方法
private void collect_comments(Map<String,Object> users) {
ArrayList<String> fetch_title = new ArrayList<>();
//iterate through each user, ignoring their UID
for (Map.Entry<String, Object> entry : users.entrySet()) {
//Get user map
Map title = (Map) entry.getValue();
Map msg = (Map) entry.getValue();
//Get phone field and append to list
fetch_title.add((String) title.get("post_title"));// Student X says:
fetch_title.add((String) msg.get("message")); // the message
post_update.setText(fetch_title.toString());
}//end of for loop
我的问题是当前的输出:
Student Billy Bob says: Hello World Student Jony Jhon says: Hello Back Student Ben Dover says: I can not read this
请帮我将我的输出格式化为: 学生比利鲍勃说:你好世界 学生 Jony Jhon 说:你好回来 学生 Ben Dover 说:我看不懂这个
如您所见,“学生比利鲍勃说:”代表“post_title”,“Hello World”是“消息”。我想在每个“post_title”+“message”之后插入一个新行。
我在闲暇时处理一些事情:
for(String s : fetch_title) {
System.out.println(s);
}
唯一的问题是我不知道如何将 System.out.println 转换为“textview”。
我也试过:
for(String s : fetch_title) {
post_update.setText(s);
}
输出只有一行(学生比利鲍勃说:Hello World),因为我在我的 xml 中添加了“singleline=false”和“minlines=1”。
<TextView
android:id="@+id/tvValue"
android:layout_width="408dp"
android:layout_height="502dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:singleLine="false"
android:minLines="1"
/>
请帮我解决这个问题。我哪里做错了?爪哇? XML?
【问题讨论】:
标签: java android arrays textview