-1

我正在尝试像这样列出哈希映射的所有值:

项目 1 值 1 项目 2 值 2 。. .

为此,我将哈希图传递给另一个活动,并在另一个活动上;我做一些这样的事情:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.orneksayisi);
        listV=(ListView)findViewById(R.id.listView1);
        ourMap=(HashMap<String, Integer>) getIntent().getSerializableExtra("ornekMap");
        String[] from = { "aktivite", "sayi" };
        int[] to = { android.R.id.text1, android.R.id.text2 };

        ArrayList<Map<String, String>> list = buildData();
        SimpleAdapter adapter = new SimpleAdapter(this, list,
                android.R.layout.simple_list_item_1, from, to);
            listV.setAdapter(adapter);
    }

   public ArrayList<Map<String,String>> buildData(){
       ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();

       list.add(putData("durus",ourMap.get("durus").toString()));
       list.add(putData("kosma",ourMap.get("kosma").toString()));
       list.add(putData("yurume",ourMap.get("yurume").toString()));
       list.add(putData("dusme",ourMap.get("dusme").toString()));
       list.add(putData("inme",ourMap.get("inme").toString()));
       list.add(putData("cikma",ourMap.get("cikma").toString()));

       return list;
   }

   private HashMap<String, String> putData(String name, String value) {

        HashMap<String, String> item = new HashMap<String, String>();
        item.put("aktivite", name);
        item.put("sayi", value);
        return item;
      }

当我尝试这个时,它只显示“键”值而不显示相反的值(一列)。我怎样才能连续显示两个值(键,值)?

4

1 回答 1

2

如何连续显示两个值(键,值)?

您需要使用显示多个条目的布局,请尝试使用android.R.layout.simple_list_item_2.

SimpleAdapter adapter = new SimpleAdapter(this, list,
        android.R.layout.simple_list_item_2, from, to);

(或编写自己的布局。)

于 2013-01-22T17:19:50.793 回答