WeatherActivity.zip
vatsag.samples.weatherdisplay.WeatherActivity
.classpath
.project
.settings
AndroidManifest.xml
assets
bin
AndroidManifest.xml
classes.dex
classes
vatsag
samples
weatherdisplay
BinderData$ViewHolder.class
BinderData.class
BuildConfig.class
R$attr.class
R$drawable.class
R$id.class
R$layout.class
R$menu.class
R$string.class
R$style.class
R.class
SampleActivity.class
WeatherActivity$1.class
WeatherActivity.class
jarlist.cache
res
drawable-hdpi
ic_action_search.png
ic_launcher.png
drawable-ldpi
ic_launcher.png
drawable-mdpi
ic_action_search.png
ic_launcher.png
drawable-xhdpi
arrow.png
cloudy.png
dcloudy.png
drainy.png
dsnowing.png
dsunny.png
dthunder.png
ic_action_search.png
ic_launcher.png
pcloudy.png
rainy.png
snowing.png
sunny.png
thunder.png
resources.ap_
vatsag.samples.weatherdisplay.WeatherActivity.apk
gen
vatsag
samples
weatherdisplay
ic_launcher-web.png
libs
android-support-v4.jar
proguard-project.txt
project.properties
res
drawable-hdpi
ic_action_search.png
ic_launcher.png
drawable-ldpi
ic_launcher.png
drawable-mdpi
ic_action_search.png
ic_launcher.png
drawable-xhdpi
layout
menu
values
values-v11
values-v14
src
vatsag
samples
weatherdisplay
|
package vatsag.samples.weatherdisplay;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class BinderData extends BaseAdapter {
// XML node keys
static final String KEY_TAG = "weatherdata"; // parent node
static final String KEY_ID = "id";
static final String KEY_CITY = "city";
static final String KEY_TEMP_C = "tempc";
static final String KEY_TEMP_F = "tempf";
static final String KEY_CONDN = "condition";
static final String KEY_SPEED = "windspeed";
static final String KEY_ICON = "icon";
LayoutInflater inflater;
ImageView thumb_image;
List<HashMap<String,String>> weatherDataCollection;
ViewHolder holder;
public BinderData() {
// TODO Auto-generated constructor stub
}
public BinderData(Activity act, List<HashMap<String,String>> map) {
this.weatherDataCollection = map;
inflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
// return idlist.size();
return weatherDataCollection.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null){
vi = inflater.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.tvCity = (TextView)vi.findViewById(R.id.tvCity); // city name
holder.tvWeather = (TextView)vi.findViewById(R.id.tvCondition); // city weather overview
holder.tvTemperature = (TextView)vi.findViewById(R.id.tvTemp); // city temperature
holder.tvWeatherImage =(ImageView)vi.findViewById(R.id.list_image); // thumb image
vi.setTag(holder);
}
else{
holder = (ViewHolder)vi.getTag();
}
// Setting all values in listview
holder.tvCity.setText(weatherDataCollection.get(position).get(KEY_CITY));
holder.tvWeather.setText(weatherDataCollection.get(position).get(KEY_CONDN));
holder.tvTemperature.setText(weatherDataCollection.get(position).get(KEY_TEMP_C));
//Setting an image
String uri = "drawable/"+ weatherDataCollection.get(position).get(KEY_ICON);
int imageResource = vi.getContext().getApplicationContext().getResources().getIdentifier(uri, null, vi.getContext().getApplicationContext().getPackageName());
Drawable image = vi.getContext().getResources().getDrawable(imageResource);
holder.tvWeatherImage.setImageDrawable(image);
return vi;
}
/*
*
* */
static class ViewHolder{
TextView tvCity;
TextView tvTemperature;
TextView tvWeather;
ImageView tvWeatherImage;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software Developer, Cinephile, Dromomaniac, Animal lover, Self proclaimed Photographer not necessarily in the same order.