2012-05-31 3 views
0

저는 ListView입니다. 각 입력은 사용자의 현재 위치와 관심 장소 간의 거리를 포함하여 일부 정보를 표시합니다.스크롤 목록 위치 간 거리 계산으로 인해 지연이 발생합니다.

불행히도 거리 계산 방법을 호출하고 TextView을 설정하는 문자열을 반환하여 getView() 내부의 거리 계산을 수행하므로 목록이 약간 뒤떨어져 있습니다.

아무도 내 솔루션을 줄 수 없으므로 내 ListView에서 부드럽게 스크롤 할 수 있습니까?

@Override 
     public View getView(final int position, View convertView, 
       ViewGroup parent) { 
      layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      FeedViewHolder feedViewHolder = null; 
      final VideoLocationDB vidLocation = videoLocationsDB[position]; 
      String url = vidLocation.documentary_thumbnail_url; 
      String name = vidLocation.name; 
      String title = vidLocation.name; 
      String desc = vidLocation.text; 
      double lat = vidLocation.latitude; 
      double lng = vidLocation.longitude; 
      String distance = calculateDistance(lat,lng); 


      if (convertView == null) { 

       convertView = layoutInflater.inflate(R.layout.listitems, parent,false); 
       feedViewHolder = new FeedViewHolder(); 
       feedViewHolder.titleView = (TextView) convertView.findViewById(R.id.txt_title); 
       feedViewHolder.descView = (TextView) convertView.findViewById(R.id.txt_list_desc); 
       feedViewHolder.more = (TextView) convertView.findViewById(R.id.txt_more); 
       feedViewHolder.distanceView = (TextView) convertView.findViewById(R.id.txt_distance); 
       feedViewHolder.v = (ImageView) convertView.findViewById(R.id.image); 

       Typeface fontRegular = Typeface.createFromAsset(getAssets(), 
         "miso.otf"); 
       feedViewHolder.titleView.setTypeface(fontRegular); 
       Typeface fontLight = Typeface.createFromAsset(getAssets(), 
         "miso-light.otf"); 
       feedViewHolder.descView.setTypeface(fontLight); 
       feedViewHolder.more.setTypeface(fontLight); 
       feedViewHolder.distanceView.setTypeface(fontRegular); 

       convertView.setTag(feedViewHolder); 

      } else 
      { 
       feedViewHolder = (FeedViewHolder) convertView.getTag(); 
      } 


      feedViewHolder.v.setTag(url); 
      loader.DisplayImage(url, LocationsListActivity.this, feedViewHolder.v, name); 
      feedViewHolder.titleView.setText(title.toUpperCase()); 
      feedViewHolder.descView.setText(desc); 
      feedViewHolder.more.setText(getString(R.string.de_list_more)); 
      feedViewHolder.distanceView.setText(distance); 

      return convertView; 
     } 

여기있는 거리 계산 방법 :

public double countDistance(double lat1, double lng1, double lat2, 
      double lng2) { 
     Location locationUser = new Location("point A"); 
     Location locationPlace = new Location("point B"); 
     locationUser.setLatitude(lat1); 
     locationUser.setLongitude(lng1); 
     locationPlace.setLatitude(lat2); 
     locationPlace.setLongitude(lng2); 

     double distance = locationUser.distanceTo(locationPlace); 

     return distance; 
    } 

    public String calculateDistance(double lat2, double lng2){ 

     String distance = null; 

     if (location != null) { 
      double lat = location.getLatitude(); 
      double lng = location.getLongitude(); 

      if (countDistance(lat, lng, lat2, lng2) >= 500) { 
       double kilometer = countDistance(lat, lng, lat2, lng2)/1000; 
       int decimalPlaces = 1; 
       BigDecimal decimal = new BigDecimal(kilometer); 
       decimal = decimal.setScale(decimalPlaces, 
         BigDecimal.ROUND_HALF_UP); 
       double new_km = decimal.doubleValue(); 
       distance = String.valueOf(new_km+ " km"); 
      } else { 
       int decimalPlaces = 1; 
       BigDecimal decimal = new BigDecimal(countDistance(lat, lng, 
         lat2, lng2)); 
       decimal = decimal.setScale(decimalPlaces, 
         BigDecimal.ROUND_HALF_UP); 
       double meter = decimal.doubleValue(); 
       distance = String.valueOf(meter + " m"); 
      } 
      videoLocationAdapter.notifyDataSetChanged(); 
     } 
     return distance; 
    } 
+0

왜 BigDecimal을 사용하고 있습니까? 두 은하계 사이의 거리를 계산하고 있습니까? – Shaiful

+0

거리의 길이를 둥글게하고 싶었 기 때문에 다른 제안이 있습니까? – hectichavana

답변

1

Greendroid (https://github.com/cyrilmottier/GreenDroid) 미래 (사용 HTTP

여기 내 getView() 방법입니다 : //docs.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html)을 사용하여 웹에서 이미지를 비동기 적으로로드 할 수 있습니다. 목록에 수백 개의 항목이 포함되어 있어도 매우 효율적입니다. 그래서 나는 이것이 당신이 찾고있는 것들의 종류라고 생각합니다. 선물은 풀을 처리하는 집행자가 관리하므로 모든 것이 하드웨어 제한 내에서 수행됩니다.

일부 코드는 무엇입니까? Greendroid 여기 흥미로운 예제가 더 많은 정보를 찾을 수 있습니다. 내 북마크에 있었지만 최신 버전인지 잘 모르겠습니다. http://blog.tomgibara.com/post/7665158012/android-adapter-view-rendering

관련 문제