如何在显示列表后删除方括号?

时间:2022-09-15 16:00:48

i declared ArrayList

我声明了ArrayList

ArrayList<ArrayList<String>> usersList1234 = new ArrayList<ArrayList<String>>(); and listview.

ArrayList > usersList1234 = new ArrayList >();和listview。

I set the ArrayList to ListView in the following way:

我通过以下方式将ArrayList设置为ListView:

ArrayAdapter adapter = new ArrayAdapter<>(SearchFriendsActivity.this, android.R.layout.simple_list_item_1, usersList1234);
        this.allUsers.setAdapter(adapter);

My list has quite a lot of elements (each element has three fields. this is how it looks:

我的列表有很多元素(每个元素有三个字段。这是它的外观:

Image1

Image2

When viewed on a virtual Android device, it looks like this ()

在虚拟Android设备上查看时,它看起来像这样()

[Text, Text, Text]

[文字,文字,文字]

[Text1, Text1, Text1]

[Text1,Text1,Text1]

[Text2, Text2, Text2]

[Text2,Text2,Text2]

Is there a way to remove these square brackets?

有没有办法删除这些方括号?

1 个解决方案

#1


2  

From the ArrayAdapter source code, if your single object inside the List you send is not an instance of CharSequence, it just uses the toString() of that object.

从ArrayAdapter源代码中,如果您发送的List中的单个对象不是CharSequence的实例,则它只使用该对象的toString()。

And ArrayList toString() adds those [] for you, you need to pass List<String> and construct the strings yourself as you wish.

并且ArrayList toString()为您添加[],您需要传递List 并根据需要自行构造字符串。

For each sub list you can do the appending yourself.

对于每个子列表,您可以自己进行追加。

#1


2  

From the ArrayAdapter source code, if your single object inside the List you send is not an instance of CharSequence, it just uses the toString() of that object.

从ArrayAdapter源代码中,如果您发送的List中的单个对象不是CharSequence的实例,则它只使用该对象的toString()。

And ArrayList toString() adds those [] for you, you need to pass List<String> and construct the strings yourself as you wish.

并且ArrayList toString()为您添加[],您需要传递List 并根据需要自行构造字符串。

For each sub list you can do the appending yourself.

对于每个子列表,您可以自己进行追加。