@Override public View getView ( int position, View convertView, ViewGroup parent ) { /* create a new view of my layout and inflate it in the row */ convertView = ( RelativeLayout ) inflater.inflate( resource, null ); /* Extract the city's object to show */ City city = getItem( position ); /* Take the TextView from layout and set the city's name */ TextView txtName = (TextView) convertView.findViewById(R.id.cityName); txtName.setText(city.getName()); /* Take the TextView from layout and set the city's wiki link */ TextView txtWiki = (TextView) convertView.findViewById(R.id.cityLinkWiki); txtWiki.setText(city.getUrlWiki()); Typeface face=Typeface.createFromAsset(getAssets(),"fonts/roboto.ttf"); txtName.setTypeface(face); txtWiki.setTypeface(face); return convertView; }
@Override public View getView ( int position, View convertView, ViewGroup parent ) { ViewHolder holder; if(convertView == null) { convertView = ( RelativeLayout ) inflater.inflate( resource, parent, false ); holder = new ViewHolder(); holder.txtName = (TextView) convertView.findViewById(R.id.cityName); holder.txtWiki = (TextView) convertView.findViewById(R.id.cityLinkWiki); holder.imageCity = (ImageView) convertView.findViewById(R.id.ImageCity); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } City city = (City)getItem( position ); holder.txtName.setText(city.getName()); holder.txtWiki.setText(city.getUrlWiki()); return convertView; }
@Override public View getView ( int position, View convertView, ViewGroup parent ) { /* create a new view of my layout and inflate it in the row */ convertView = ( RelativeLayout ) inflater.inflate( resource, null ); /* Extract the city's object to show */ City city = getItem( position ); /* Take the TextView from layout and set the city's name */ TextView txtName = (TextView) convertView.findViewById(R.id.cityName); txtName.setText(city.getName()); /* Take the TextView from layout and set the city's wiki link */ TextView txtWiki = (TextView) convertView.findViewById(R.id.cityLinkWiki); txtWiki.setText(city.getUrlWiki()); /* Take the ImageView from layout and set the city's image */ ImageView imageCity = (ImageView) convertView.findViewById(R.id.ImageCity); String uri = "drawable/" + city.getImage(); int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName()); Drawable image = context.getResources().getDrawable(imageResource); imageCity.setImageDrawable(image); return convertView; }
txtWiki.setText(city.getUrlWiki());