android多个列表,android中的嵌套列表与多个xml文件中的listview

您只需解析XML并按照SimpleExpandableListAdapter类支持的格式构造数据即可。

1)适合人群 List> lstGroups

2)组 List>> lstGroupItems

的子项,然后你可以使用SimpleExpandableListAdapter

SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(

getApplicationContext(), lstGroups,

R.layout.group_row, // Group item layout XML.

new String[] { "Group Item" }, // the key that will identify group in `lstGroups`.

new int[] { R.id.row_name }, // ID of each group item.-Data

lstGroupItems, // childData describes second-level

R.layout.child_row, // Layout for sub-level entries(second level).

new String[] { "Sub Item" }, // Keys that will identify child items in `lstGroupItems`

new int[] { R.id.grp_child }

);

setListAdapter(expListAdapter);

你可以参考这个例子

补充:

我认为你应该使用SQLiteDatabase如果你有大量的数据,否则你可以在下面的格式结构数据

Map> mapHouses;

这里的关键将是房屋名称及其价值将再次成为将持有房屋性质和相应价值的地图。

您将需要访问mapHouses不同活动,因此您可以在您的应用程序环境中具有相同的类别,例如Application类,并将房屋名称传递给要显示房屋详细信息的活动。但是,如果您的应用程序被Android杀死,您最终会将大量数据存入内存,并且可能会丢失大量数据。

仿某团list里嵌套list\ package com.zl.listview; import java.util.ArrayList; import java.util.HashMap; import com.kjy.kjylistview.R; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.Toast; /** * @author zl * @time 2014年12月24日15:37:18 */ public class QianTaoListviewActivity extends Activity { private ListView listView; private ArrayList<HashMap<String, Object>> parentList, childList; private ParentAdapter parentAdapter; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_qiantao); init(); } private void init() { listView = (ListView) findViewById(R.id.qiantao_lv); getList(); } private void getList() { parentList = new ArrayList<HashMap<String, Object>>(); for (int i = 1; i < 10; i++) { childList = new ArrayList<HashMap<String, Object>>(); for (int j = i < 7 ? i : 7; j < 9; j++) { HashMap<String, Object> ParentMap = new HashMap<String, Object>(); ParentMap.put("parent_title", "三木铁板烧" + i); ParentMap.put("parent_address", "8." + i); ParentMap.put("parent_distance", "1" + i); ParentMap.put("parent_distance1", "已售123" + i); childList.add(ParentMap); } HashMap<String, Object> map = new HashMap<String, Object>(); map.put("child_item_title", "九州八拖二火锅" + i); map.put("child_item_price_old", "4." + i + "分"); map.put("child_item_price_score", "(100人)"); map.put("parent_lv", childList); parentList.add(map); } parentAdapter = new ParentAdapter(parentList, QianTaoListviewActivity.this); listView.setAdapter(parentAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Intent intent = new Intent(QianTaoListviewActivity.this, Activity_1.class); Toast.makeText(QianTaoListviewActivity.this, "第" + arg2 + "个目", Toast.LENGTH_LONG).show(); startActivity(intent); } }); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值