如何将此List<Map<String,?>> items = new LinkedList<Map<String,?>>();
存储到变量数组并创建其倍数。我是新手,我有点混淆我如何使用它。
我正在为listview创建节标题,这就是为什么我需要多个item
,因为它是我的数据源,而我将生成的标题数量取决于我检索的项目类型。 / p>
这是我到目前为止所尝试的:
listView = (ListView)findViewById(R.id.listView2);
items = new LinkedList<Map<String,?>>();
// create our list and custom adapter
SeparatedListAdapter adapter = new SeparatedListAdapter(this);
int index = 0;
String storeName = "";
String d = handler.getStoreList().get(index).toString();
for(int innerCounter = 0; innerCounter < handler.getItemList().size(); innerCounter ++) {
//Items to display in the row
String itemName = handler.getItemList().get(innerCounter).toString();
String category = handler.getPriceList().get(innerCounter).toString();
//this data is the storeName that should
//be the section header and be compared if change
//of store is detected to create new header
storeName = handler.getStoreList().get(innerCounter).toString();
if (storeName.equals(d)){
Log.i("Items", d);
//add items if the storeName does change
items.add(createItem(itemName, category));
}
else {
// else if storeName change create a section and
// put the data inside
adapter.addSection(d, new SimpleAdapter(this, items, R.layout.listview_format,
new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.item_list, R.id.list_complex_caption }));
Log.i("Header", "Sucessfully create new header");
// create new instance of items to for another checking
List<Map<String,?>> items = new LinkedList<Map<String,?>>();
items.add(createItem(itemName, category));
Log.i("Items", d);
// change the header
d = handler.getStoreList().get(index+1).toString();
adapter.addSection(d, new SimpleAdapter(this, items, R.layout.listview_format,
new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.item_list, R.id.list_complex_caption }));
}
}
listView.setAdapter(adapter);
listView.setOnItemClickListener( new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position ,
long id) {
HashMap<String, String> mymap = (HashMap<String, String>) arg0.getItemAtPosition(position);
String selectedItem =mymap.get(ITEM_TITLE);
intent = new Intent(TechiesActivity.this,ItemInfoActivity.class);
intent.putExtra("key", selectedItem);
intent.putExtra("className", "Techies");
startActivity(intent);
}
});
}