我有一个listvew,我像这段代码一样将子项添加到listview中
public class MyCustomListView extends Activity {
/** Called when the activity is first created. */
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_list_view);
lv=(ListView) this.findViewById(R.id.lvvv);
SimpleAdapter adapter = new SimpleAdapter(this,list, R.layout.custom_row_view,new String[] {"pen","color"},
new int[] {R.id.text1, R.id.text3}
);
populateList();
lv.setAdapter(adapter);
}
static final ArrayList<HashMap<String,String>> list =
new ArrayList<HashMap<String,String>>();
private void populateList() {
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("pen","MONT Blanc");
temp.put("color", "Black");
list.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("pen","Gucci");
temp1.put("color", "Red");
list.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("pen","Parker");
temp2.put("color", "Blue");
}
}
但是在颜色键中,如果我的笔有很多颜色,我想将颜色排列成一个列表,这个颜色列表在笔下面。
前任:
-笔:帕克。
+颜色:蓝色。
+颜色:红色。
我该怎么做?请帮我!非常感谢。