Fixed layout in paranomio and loading views in wiki listview.

master
Tomasz Półgrabia 2016-09-16 23:58:52 +02:00
parent 4c30cf03df
commit 7ff3f73cdd
4 changed files with 31 additions and 17 deletions

View File

@ -1,6 +1,7 @@
package pl.tpolgrabia.urbanexplorer.adapters;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -25,22 +26,25 @@ public class WikiLocationsAdapter extends ArrayAdapter<WikiAppObject> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView;
if (convertView != null) {
// reusing old view
inflatedView = convertView;
} else {
inflatedView = inflater.inflate(R.layout.wiki_locations_item,parent,false);
}
View itemView;
// reusing old view
itemView = convertView != null ? convertView : inflater.inflate(R.layout.wiki_locations_item, parent, false);
WikiAppObject wikiPage = getItem(position);
if (wikiPage.getPageId() != null && wikiPage.getPageId().equals(itemView.getTag())) {
// all data were previously loaded
return itemView;
}
itemView.setTag(wikiPage.getPageId());
// wiki page image preview
ImageView imgPreview = (ImageView) inflatedView.findViewById(R.id.wiki_locs_item_img_preview);
ImageView imgPreview = (ImageView) itemView.findViewById(R.id.wiki_locs_item_img_preview);
String url = wikiPage.getThumbnail() != null ? wikiPage.getThumbnail() : null;
TextView locDistanceInfo = (TextView) inflatedView.findViewById(R.id.wiki_locs_item_distance);
TextView locDistanceInfo = (TextView) itemView.findViewById(R.id.wiki_locs_item_distance);
locDistanceInfo.setText("" + wikiPage.getDistance() / 1000.0 + " km");
imgPreview.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.noimage));
if (url != null) {
ImageLoader.getInstance().displayImage(
@ -50,10 +54,10 @@ public class WikiLocationsAdapter extends ArrayAdapter<WikiAppObject> {
}
// wiki page title
TextView pageTitle = (TextView) inflatedView.findViewById(R.id.wiki_locs_item_title);
TextView pageTitle = (TextView) itemView.findViewById(R.id.wiki_locs_item_title);
pageTitle.setText(wikiPage.getTitle());
return inflatedView;
return itemView;
}
}

View File

@ -1,6 +1,7 @@
package pl.tpolgrabia.urbanexplorer.fragments;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
@ -31,13 +32,21 @@ public class PanoramioAdapter extends ArrayAdapter<PanoramioImageInfo> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.location_item, parent, false);
View itemView = convertView != null ? convertView : inflater.inflate(R.layout.location_item, parent, false);
final PanoramioImageInfo item = getItem(position);
if (item.getPhotoId() != null && item.getPhotoId().equals(itemView.getTag())) {
// if it is the the same object f.e. add new objects to the collection (without the slide)
// the refresh makes blinking without this
return itemView;
}
TextView locDesc = (TextView) itemView.findViewById(R.id.location_description);
locDesc.setText(getItem(position).getPhotoTitle());
final String photoUrl = getItem(position).getPhotoFileUrl();
itemView.setTag(item.getPhotoId());
locDesc.setText(item.getPhotoTitle());
final String photoUrl = item.getPhotoFileUrl();
ImageView photoImg = (ImageView) itemView.findViewById(R.id.photo_img);
// photoImg.setImageBitmap(bm);
// photoImg.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_launcher));
photoImg.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.noimage));
ImageLoader.getInstance().displayImage(photoUrl, photoImg, MainActivity.options);
return itemView;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -7,7 +7,8 @@
<ImageView
android:id="@+id/photo_img"
android:layout_width="80dp"
android:layout_height="80dp" />
android:layout_height="80dp"
android:layout_marginRight="10dp"/>
<TextView
android:id="@+id/location_description"