如何在HashMap Android中删除大括号

时间:2014-06-03 08:36:49

标签: java android hashmap spinner curly-braces

我有用于spinnner的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 =计算机编程}

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

更改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);