gpt4 book ai didi

java - 如何删除 HashMap Android 中的大括号

转载 作者:搜寻专家 更新时间:2023-11-01 08:50:23 24 4
gpt4 key购买 nike

我有微调器的 ArrayAdapter,我想将项目添加到这个微调器。我的代码如下

public void parser()
{
final ArrayList<HashMap<String, String>> valuesList = new ArrayList<HashMap<String,String>>();

for(int i = 0;i<response.getPropertyCount();i++){
SoapObject dersListesi = (SoapObject)response.getProperty(i);
for (int j = 0; j < dersListesi.getPropertyCount(); j++) {
Object objectNames = dersListesi.getProperty(j);

SoapObject ders_kodu = (SoapObject)objectNames;
SoapObject ders_adi = (SoapObject)objectNames;
HashMap<String, String> map = new HashMap<String, String>();

String dersKodu = ders_kodu.getProperty("dersKodu").toString();

String dersAdi = ders_adi.getProperty("dersAdi").toString();

map.put( dersKodu,dersAdi);

valuesList.add(map);
System.out.println( "map"+map);
System.out.println(dersAdi);
}
ArrayAdapter<HashMap<String, String>> ad =
new ArrayAdapter<HashMap<String,String>>(this,
android.R.layout.simple_list_item_1,valuesList);
ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDersKodu = (Spinner)findViewById(R.id.derscombo);
spinnerDersKodu.setAdapter(ad);


}

}

这段代码工作正常,但我的微调器的输出是这样的:

{BIM101=计算机编程}

如何删除这些花括号和 =?

感谢您的帮助。

最佳答案

更改您的 ArrayAdapter 以保存字符串实例。您不需要 HashMap 的 ArrayList,如果它的目的只是打印 HashMap 的键和值

final ArrayList<String> valuesList = new ArrayList<String>();
for(int i = 0;i<response.getPropertyCount();i++){
SoapObject dersListesi = (SoapObject)response.getProperty(i);
for (int j = 0; j < dersListesi.getPropertyCount(); j++) {
Object objectNames = dersListesi.getProperty(j);
SoapObject ders_kodu = (SoapObject)objectNames;
SoapObject ders_adi = (SoapObject)objectNames;
String dersKodu = ders_kodu.getProperty("dersKodu").toString();
String dersAdi = ders_adi.getProperty("dersAdi").toString();
valuesList.add(dersKodu+ " " + dersAdi);
}
ArrayAdapter<String> ad =
new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,valuesList);

关于java - 如何删除 HashMap Android 中的大括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24010595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com