how can i sort linearlayout data by name and type in android?
LinearLayout lin2 = new LinearLayout(this); lin2.setOrientation(LinearLayout.VERTICAL);
LinearLayout lin3 = new LinearLayout(this);
lin3.setOrientation(LinearLayout.HORIZONTAL);
mapfeautre.put("name",node.getAttributes().getNamedItem("name").getNodeValue());
TextView txtfeaturename = new TextView(this);
txtfeaturename.setTextColor(Color.WHITE);
txtfeaturename.setPadding(5, 0, 0, 0);
String strtxtfeaturename =mapfeautre.put("name",node.getAttributes().getNamedItem("name").getNodeValue());
txtfeaturename.setText(strtxtfeaturename);
lin3.addView(txtfeaturename);
mapfeautre.put("distance",node.getAttributes().getNamedItem("distance").getNodeValue());
TextView txtfeaturedistance = new TextView(this);
txtfeaturedistance.setTextColor(Color.WHITE);
txtfeaturedistance.setPadding(90, 0, 0, 0);
String strtxtfeatur开发者_运维知识库edistance =mapfeautre.put("distance",node.getAttributes().getNamedItem("distance").getNodeValue());
txtfeaturedistance.setText(strtxtfeaturedistance+"ml");
lin3.addView(txtfeaturedistance);
lin2.addView(lin3);
//mainlinear.addView(lin2);
LinearLayout linsecond = new LinearLayout(this);
linsecond.setOrientation(LinearLayout.HORIZONTAL);
mapfeautre.put("venuetype",node.getAttributes().getNamedItem("venuetype").getNodeValue());
TextView txtfeaturevenuetype = new TextView(this);
txtfeaturevenuetype.setTextColor(Color.WHITE);
String strtxtfeaturevenuetype =mapfeautre.put("venuetype",node.getAttributes().getNamedItem("venuetype").getNodeValue());
txtfeaturevenuetype.setText(strtxtfeaturevenuetype+"-");
linsecond.addView(txtfeaturevenuetype);
mapfeautre.put("othervenuetype",node.getAttributes().getNamedItem("othervenuetype").getNodeValue());
TextView txtfeatureothervenuetype = new TextView(this);
txtfeatureothervenuetype.setTextColor(Color.WHITE);
String strtxtfeatureothervenuetype =mapfeautre.put("othervenuetype",node.getAttributes().getNamedItem("othervenuetype").getNodeValue());
txtfeatureothervenuetype.setText(strtxtfeatureothervenuetype);
linsecond.addView(txtfeatureothervenuetype);
mapfeautre.put("phonenumber",node.getAttributes().getNamedItem("phonenumber").getNodeValue());
TextView txtfeaturephonenumber = new TextView(this);
txtfeaturephonenumber.setTextColor(Color.WHITE);
String strtxtfeaturephonenumber =mapfeautre.put("phonenumber",node.getAttributes().getNamedItem("phonenumber").getNodeValue());
txtfeaturephonenumber.setText(strtxtfeaturephonenumber);
linsecond.addView(txtfeaturephonenumber);
lin2.addView(linsecond);
//TextView txtaddress = new TextView(this);
LinearLayout linthy = new LinearLayout(this);
linthy.setOrientation(LinearLayout.HORIZONTAL);
mapfeautre.put("address",node.getAttributes().getNamedItem("address").getNodeValue());
TextView txtfeatureaddress = new TextView(this);
txtfeatureaddress.setTextColor(Color.WHITE);
String strtxtfeatureaddress =mapfeautre.put("address",node.getAttributes().getNamedItem("address").getNodeValue());
txtfeatureaddress.setText(strtxtfeatureaddress+",");
linthy.addView(txtfeatureaddress);
//lin2.addView(linsecond);
//mainlinear.addView(lin2);
//lin.addView(mainlinear);
mapfeautre.put("zip",node.getAttributes().getNamedItem("zip").getNodeValue());
TextView txtfeaturezip = new TextView(this);
txtfeaturezip.setTextColor(Color.WHITE);
String strtxtfeaturezip =mapfeautre.put("zip",node.getAttributes().getNamedItem("zip").getNodeValue());
txtfeaturezip.setText(strtxtfeaturezip);
linthy.addView(txtfeaturezip);
lin2.addView(linthy);
mainlinear.addView(lin2);
linhh.addView(mainlinear);
linm.addView(linhh);
//dataListfeture.add(mapfeautre);
dataListfeture.add(j, mapfeautre);
mylistfeature.add(j,mapfeautre);.
guys help me how can i sort my data in linear layout by name and type.
I think there it is not possible to to sort a LinearLayout directly.
We have sort the Sting and then give it to LinearLayout in sorted order.
To sort the String following code is the easy solution.
Map<String, String> sortedMap1;
sortedMap1=new TreeMap<String, String>(StringArray);
精彩评论