Java 如何在ListView中显示HashMap中的项和子项

Java 如何在ListView中显示HashMap中的项和子项,java,android,Java,Android,我想显示HashMap中的项目和子项目,项目是字符串(借款人名称),子项目是双(借款人贷款)。这是我的第一款android应用,所以请理解:) 这是我的布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" a

我想显示HashMap中的项目和子项目,项目是字符串(借款人名称),子项目是双(借款人贷款)。这是我的第一款android应用,所以请理解:)

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="669dp">

    </ListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <Button
            android:id="@+id/editButton"
            android:layout_width="244dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Dodaj" />

        <Button
            android:id="@+id/sumButton"
            android:layout_width="202dp"
            android:layout_height="wrap_content"
            android:text="Suma dlugow" />

    </LinearLayout>

</LinearLayout>

或者只是John\t 300

您当前的代码只是获取整个地图的
字符串
值。您需要在映射上迭代以获取键和值,然后构造新的
字符串
,并将其添加到
列表

for (Map.Entry<String, Double> entry : borrowers.entrySet()) {
    String key = entry.getKey();
    Double value = entry.getValue();
    arrayList.add(key + "\t" + value);
}
for(Map.Entry:借款人.entrySet()){
String key=entry.getKey();
Double value=entry.getValue();
arrayList.add(键+“\t”+值);
}
John
300.0
for (Map.Entry<String, Double> entry : borrowers.entrySet()) {
    String key = entry.getKey();
    Double value = entry.getValue();
    arrayList.add(key + "\t" + value);
}