【问题标题】:how can i sort linearlayout data by name and type in android?我如何按名称对线性布局数据进行排序并在android中输入?
【发布时间】:2011-07-15 21:04:21
【问题描述】:

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 strtxtfeaturedistance =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);.

各位帮我如何按名称和类型对线性布局中的数据进行排序。

【问题讨论】:

    标签: android


    【解决方案1】:

    我认为不可能直接对 LinearLayout 进行排序。

    我们已经对 Sting 进行了排序,然后按排序顺序将其提供给 LinearLayout。

    按照以下代码对字符串进行排序是一种简单的解决方案。

    Map<String, String>  sortedMap1;
    
    sortedMap1=new TreeMap<String, String>(StringArray);
    

    【讨论】:

    • 你好,伙计,我明白你的意思,但如果可能的话,请给我一个示例演示
    猜你喜欢
    • 1970-01-01
    • 2018-10-09
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 2010-11-24
    相关资源
    最近更新 更多