Android Open Source - android-weather-demo-application City Adapter






From Project

Back to project page android-weather-demo-application.

License

The source code is released under:

GNU General Public License

If you think the Android project android-weather-demo-application listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.openweathermap.adapter;
//  ww  w .ja va2  s .  c  om
import org.openweathermap.sql.model.CityModel;
import org.openweathermap.utils.StringHelper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ink.weather.R;

/**
 * An adapter to display a list of City DTO using the view_city_list_item layout resource
 * @author samkirton
 */
public class CityAdapter extends ArrayAdapter<CityModel> {
  private final Context mContext;
  private final CityModel[] mValues;

  public CityAdapter(Context context, CityModel[] values) {
    super(context, R.layout.view_city_list_item, values);
    this.mContext = context;
    this.mValues = values;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    
    if (convertView == null) {
      LayoutInflater inflater = LayoutInflater.from(mContext);
      convertView = (View)inflater.inflate(R.layout.view_city_list_item, parent, false);
      
      viewHolder = new ViewHolder();
      viewHolder.uiTitleTextView = (TextView)convertView.findViewById(R.id.view_city_list_title);
      viewHolder.uiLocationTextView = (TextView)convertView.findViewById(R.id.view_city_list_location);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder)convertView.getTag();
    }
      
    // get the city name and location coords from the CityDTO
      CityModel cityModel = mValues[position];
      String displayValue = cityModel.getName() + " (" + cityModel.getCountry() + ")";
      String locationCoords = StringHelper.buildLocationString(
        cityModel.getLatitude(),
        cityModel.getLongitude()
      );
      
      viewHolder.uiTitleTextView.setText(displayValue);
      viewHolder.uiLocationTextView.setText(locationCoords);
      
      return convertView;
  }
  
  /**
   * A static class that is used to hold a reference of the row view 
   * in memory so that multiple views do not need to be inflated 
   * for the same common row layout
   */
  private static class ViewHolder {
    TextView uiTitleTextView;
        TextView uiLocationTextView;
  }
}




Java Source Code List

org.openweathermap.WeatherApplication.java
org.openweathermap.activity.MainActivity.java
org.openweathermap.activity.base.BaseActivity.java
org.openweathermap.adapter.CityAdapter.java
org.openweathermap.adapter.ForecastAdapter.java
org.openweathermap.asynctask.GetCitiesAsyncTask.java
org.openweathermap.asynctask.GetLastCityAsyncTask.java
org.openweathermap.asynctask.SaveForecastAsyncTask.java
org.openweathermap.asynctask.SearchCitiesAsyncTask.java
org.openweathermap.asynctask.base.BaseAsyncTask.java
org.openweathermap.asynctask.base.BaseResponse.java
org.openweathermap.asynctask.base.IParam.java
org.openweathermap.asynctask.param.SaveForecastParam.java
org.openweathermap.asynctask.param.SearchCitiesParam.java
org.openweathermap.asynctask.response.GetCitiesResponse.java
org.openweathermap.asynctask.response.GetLastCityResponse.java
org.openweathermap.asynctask.response.SaveForecastResponse.java
org.openweathermap.dto.CityDTO.java
org.openweathermap.dto.CoordDTO.java
org.openweathermap.dto.DayDTO.java
org.openweathermap.dto.ResultDTO.java
org.openweathermap.dto.TempDTO.java
org.openweathermap.dto.WeatherDTO.java
org.openweathermap.dto.base.IDTO.java
org.openweathermap.fragment.ForecastFragment.java
org.openweathermap.fragment.ModalDialogFragment.java
org.openweathermap.fragment.SelectCountryFragment.java
org.openweathermap.sql.SQLInitProvider.java
org.openweathermap.sql.model.CityModel.java
org.openweathermap.sql.model.IconModel.java
org.openweathermap.sql.model.WeatherModel.java
org.openweathermap.utils.DateHelper.java
org.openweathermap.utils.RESTProvider.java
org.openweathermap.utils.ReflectionHelper.java
org.openweathermap.utils.ResourceHelper.java
org.openweathermap.utils.StringHelper.java
org.openweathermap.view.CityListItemView.java
org.openweathermap.view.DateDisplayView.java
org.openweathermap.view.ViewPagerFade.java
org.openweathermap.view.ViewPagerIndicatorView.java
org.openweathermap.view.WeatherDataRowView.java
org.openweathermap.volley.callback.VolleyResponseCallback.java
org.openweathermap.volley.provider.VolleyImageLoader.java
org.openweathermap.volley.provider.VolleyRequest.java