android map自动排序,如何在Android中对阵列列表hashmap进行排序?

在Android应用开发中,从XML数据中提取信息并存储到HashMap中,然后将其显示在动态线性布局中。现在面临的问题是如何根据名称和数据类型对HashMap进行排序,以便在列表中按特定顺序显示哈希值。目前的代码创建了多个TextView来展示HashMap的内容,但未实现排序功能。
摘要由CSDN通过智能技术生成

我已经从网站获取数据并将该数据值转换为散列表。我还创建动态线性布局并在其中显示ol hashmap值。现在问题出现时,我想按名称和数据类型显示哈希值,我该怎么做?如何在Android中对阵列列表hashmap进行排序?

for (int i = 0; i < nodes.getLength(); i++)

{

Element e = (Element) nodes.item(i);

Node node = nodes.item(i);

HashMap map = new HashMap();

lin = new LinearLayout(this);

lin.setOrientation(LinearLayout.VERTICAL);

lin.setBackgroundResource(R.drawable.my_border);

LinearLayout linbsc = new LinearLayout(this);

linbsc.setOrientation(LinearLayout.HORIZONTAL);

map.put("name",node.getAttributes().getNamedItem("name").getNodeValue());

TextView txtbasicname = new TextView(this);

txtbasicname.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1f));

//txtbasicname.setBackgroundColor(Color.WHITE);

txtbasicname.setTextColor(Color.WHITE);

String strbasicname =map.put("name",node.getAttributes().getNamedItem("name").getNodeValue());

txtbasicname.setText(strbasicname);

linbsc.addView(txtbasicname);

lin.addView(linbsc);

LinearLayout linthrd = new LinearLayout(this);

linthrd.setOrientation(LinearLayout.HORIZONTAL);

map.put("venuetype",node.getAttributes().getNamedItem("venuetype").getNodeValue());

TextView txtbasicvenuetype = new TextView(this);

txtbasicvenuetype.setTextColor(Color.WHITE);

txtbasicvenuetype.setPadding(5, 0, 0, 0);

String strbasicvenuetype =map.put("venuetype",node.getAttributes().getNamedItem("venuetype").getNodeValue());

txtbasicvenuetype.setText(strbasicvenuetype+"-");

linthrd.addView(txtbasicvenuetype);

lin.addView(linthrd);

LinearLayout linforth = new LinearLayout(this);

linforth.setOrientation(LinearLayout.HORIZONTAL);

map.put("address",node.getAttributes().getNamedItem("address").getNodeValue());

TextView txtbasicaddress = new TextView(this);

txtbasicaddress.setPadding(5, 0, 0, 0);

txtbasicaddress.setTextColor(Color.WHITE);

String strbasicaddress =map.put("address",node.getAttributes().getNamedItem("address").getNodeValue());

txtbasicaddress.setText(strbasicaddress+",");

linforth.addView(txtbasicaddress);

map.put("city",node.getAttributes().getNamedItem("city").getNodeValue());

TextView txtbasiccity = new TextView(this);

txtbasiccity.setTextColor(Color.WHITE);

String strbasiccity =map.put("city",node.getAttributes().getNamedItem("city").getNodeValue());

txtbasiccity.setText(strbasiccity+",");

linforth.addView(txtbasiccity);

LinearLayout linfifth = new LinearLayout(this);

linfifth.setOrientation(LinearLayout.HORIZONTAL);

map.put("zip",node.getAttributes().getNamedItem("zip").getNodeValue());

TextView txtbasiczip = new TextView(this);

txtbasiczip.setTextColor(Color.WHITE);

txtbasiczip.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT, 1f));

String strbasiczip =map.put("zip",node.getAttributes().getNamedItem("zip").getNodeValue());

txtbasiczip.setText(strbasiczip+".");

linfifth.addView(txtbasiczip);

lin.addView(linfifth);

linm.addView(lin);

dataList.add(map);

mylist.add(map);

}

System.out.println("data list = "+dataList);

System.out.println("data list = "+dataListfeture);

+0

你可以把关于你存储在HashMap中的数据的细节作为关键和值来放入。比如什么是关键,哪些数据是有价值的。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值