安卓工作室排序列表视图包含一个文本视图,其中我显示距离和距离是在运行时计算,即不是从arraylist计算 [英] Android studio sorting listview that contain a textview in which I m showing distance and distance is calculating at runtime ie not from arraylist

查看:84
本文介绍了安卓工作室排序列表视图包含一个文本视图,其中我显示距离和距离是在运行时计算,即不是从arraylist计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android工作室排序列表视图,其中包含一个textview,其中显示距离和距离是在运行时计算,即不是来自arraylist或Sqlite,我想根据距离对列表视图进行排序,并限制listview只显示50项



我尝试过:



Android studio sorting listview that contain a textview in which i m showing distance and distance is calculating at runtime ie not from arraylist or Sqlite , I want to sort list view based on distance and also restrict listview to show only 50 items

What I have tried:

list.setAdapter(new BaseAdapter() {
    // @Override
    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        View v = getLayoutInflater().inflate(R.layout.single_row, null);
        TextView i,n,e,p;
        // i=(TextView)v.findViewById(R.id.textView1);
        n=(TextView)v.findViewById(R.id.textView2);
        e=(TextView)v.findViewById(R.id.textView3);
        p=(TextView)v.findViewById(R.id.textView6);
        Employee emp = employees.get(arg0);
        // i.setText(emp.getId());
        e.setText(emp.getAddress());
        n.setText(emp.getName());
        //new code for lat distance
        double lat =Double.parseDouble(emp.getLat());
        double log = Double.parseDouble(emp.getLog());
        /*  Intent mIntent = getIntent();
            String flatvalue = mIntent.getStringExtra("flat");
            String flogvalue = mIntent.getStringExtra("flog");
            double flat =Double.parseDouble(flatvalue.toString());
            double flog = Double.parseDouble(flogvalue.toString());*/
        if(gps.canGetLocation()){
            double flat = gps.getLatitude();
            double flog = gps.getLongitude();
            double dis = geoCoordToMeter(flat, flog, lat,log);
            int distnace =(int) dis;
            p.setText(String.valueOf(distnace) + " km" );
        }
        return v;
    }

推荐答案

将您的元素添加到列表< t>,然后使用收集(Java Platform SE 6) [ ^ ]。排序在该列表中。然后,您可以提取所需的项目并将其添加到Listview,或使用派生列表作为源。
Add your elements to a List<t>, then use Collections (Java Platform SE 6)[^].Sort on that list. You can then extract the items you want and add them to the Listview, or use a derived list as source.


这篇关于安卓工作室排序列表视图包含一个文本视图,其中我显示距离和距离是在运行时计算,即不是从arraylist计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆