Android如何为微调器添加字幕,而不是在操作栏中

时间:2013-10-03 15:12:02

标签: java android spinner android-spinner

我有一个带有ID和标题的微调器,我希望在微调器的每个部分显示ID更大,标题更小。

我该怎么做?

 Spinner spinner = (Spinner)findViewById(R.id.spinner1);
 ArrayList<String> spinnerArray = new ArrayList<String>();
        for(int i = 0; i<jArray.length();i++){
             JSONObject json_data = jArray.getJSONObject(i);            

             spinnerArray.add(json_data.getString("SessionId"));
             map.put(json_data.getString("SessionId"), json_data.getString("Title"));

        }
        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, spinnerArray);
        spinner.setAdapter(spinnerArrayAdapter);

我想要的例子:

enter image description here

1 个答案:

答案 0 :(得分:1)

修正了它。

  ArrayList<Map<String, String>> spinnerArray = new ArrayList<Map<String, String>>();

    for(int i = 0; i<jArray.length();i++){
         JSONObject json_data = jArray.getJSONObject(i);            

         Map<String, String> data = new HashMap<String, String>(2);
         data.put("SessionId", json_data.getString("SessionId"));
         data.put("Title", json_data.getString("Title"));
         spinnerArray.add(data);
         //map.put(json_data.getString("SessionId"), json_data.getString("Title"));
         Button button1 = (Button)findViewById(R.id.Submit);
         button1.setEnabled(true);

    }
      SimpleAdapter adapter = new SimpleAdapter(this, spinnerArray, android.R.layout.two_line_list_item,

               new String[] {"SessionId", "Title"},
               new int[] {android.R.id.text1,
                          android.R.id.text2});

      spinner.setAdapter(adapter);