简体   繁体   中英

How to Remove Curly Braces in HashMap Android

I have ArrayAdapter for spinnner and i want to add item to this spinner. My code like below

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


    }

}

This code work correctly but my spinner's output like this:

{BIM101=Computer Programming}

How I can remove these curly braces and = ?

Thanks for help.

Change the your ArrayAdapter to hold string instance. You do not need an ArrayList of HashMap, if the purpose it's just printing the key and the value of the 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM