Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: I tried to display list of images in Listview but i have only the first item from the list

Haya SVU:

I am working with android and retrofit to call API web services the data was received successfully but when I tried to display the list of images in my layout the result is only the first images although the size of images array is upper .. My activities is : CityActivity get city info like name and description and list of city images.. and in city images, i have the problem which I asked about my code: CityActivity:


package com.example.android.travelandtourism.Activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.android.travelandtourism.Adapters.ImagesAdapter;
import com.example.android.travelandtourism.Interfaces.IApi;
import com.example.android.travelandtourism.Models.City;
import com.example.android.travelandtourism.Models.Countries;
import com.example.android.travelandtourism.Models.Images;
import com.example.android.travelandtourism.R;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
* Created by haya on 29/08/2017.
*/

public class CityActivity extends AppCompatActivity {
private ListView listView;
public static final String BASE_URL = "http://ift.tt/2wrwbQp";
String url="http://ift.tt/2vSp9Ax";


Gson gson = new GsonBuilder()
.setDateFormat("66yyyy-MM-dd'T'HH:mm:ssZ")
.create();

Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();

IApi service = retrofit.create(IApi.class);

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_city_info);

Intent intent = this.getIntent();
int cityId = intent.getIntExtra(Intent.EXTRA_TEXT,0);

listView = (ListView) findViewById(R.id.listCityImages);
Call call = service.getCity(cityId);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
listView.setVisibility(View.VISIBLE);
ResponseValue cityResponse = response.body();
City cc = cityResponse.getCity();
TextView tv1 = (TextView) findViewById(R.id.tvCityInfoNameEn);
tv1.setText(cc.getNameEn());
TextView tv2 = (TextView) findViewById(R.id.tvCityInfoNameAr);
tv2.setText(cc.getNameAr());
TextView tv3 = (TextView) findViewById(R.id.tvCityInfoDesEng);
tv3.setText(cc.getDescriptionEn());
TextView tv4 = (TextView) findViewById(R.id.tvCityInfoDesAr);
tv4.setText(cc.getDescriptionAr());

ArrayList arrayList = new ArrayList();
ArrayList images = cityResponse.getCity().getImages();
arrayList.addAll(images);
// final ImagesAdapter adapter = new ImagesAdapter(getApplicationContext(),R.layout.row_image,arrayList);
ImagesAdapter adapter = new ImagesAdapter(getApplicationContext(),arrayList);
listView.setAdapter(adapter);


}

@Override
public void onFailure(Call call, Throwable t) {

}
});


}
}

ImagesAdapter:


package com.example.android.travelandtourism.Adapters;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.android.travelandtourism.Models.City;
import com.example.android.travelandtourism.Models.Images;
import com.example.android.travelandtourism.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
* Created by haya on 29/08/2017.
*/

public class ImagesAdapter extends BaseAdapter {

String url = "http://ift.tt/2vSp9Ax";
private Context context;
private List imagesList;

public ImagesAdapter(Context context, List objects) {
// super(context, resource, objects);
this.context = context;
this.imagesList = objects;
}


@Override
public int getCount() {

return imagesList.size();
}

@Override
public Object getItem(int position) {

return imagesList.get(position);
}

@Override
public long getItemId(int position) {

return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.row_image,parent,false);


Images image = imagesList.get(position);
ImageView iv = (ImageView)view.findViewById(R.id.ivImage);
String imgPath = image.getPath().substring(1);
Picasso.with(this.context).load(url+imgPath).resize(300,300).into(iv);


return view;

}


}

My layouts: activity_city_info:




android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://ift.tt/LrGmb4"
android:fillViewport="true">


android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">



android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvCityInfoNameEn"
android:text="EngName"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvCityInfoNameAr"
android:text="ArName"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">


android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvCityInfoDesEng"
android:text="EngDes"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvCityInfoDesAr"
android:text="ArDes"/>







android:id="@+id/listCityImages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:listitem="@layout/row_image"
/>










and finaly row_image:




android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="4dp">




android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp">
android:id="@+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />






any help! and thank you Update



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: I tried to display list of images in Listview but i have only the first item from the list

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×