I am trying to create android app with image gallery created with grid view using image adapter which fetch data using picasso library.but no image is displayed.It may be a problem of context or in picasso library but i am not sure where is the problem as i get no error.everything works fine according to Logs
**package com.example.android.popmovies;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
/**
* A placeholder fragment containing a simple view.
*/
public class PopMovieFragment extends Fragment {
ImageAdapter imageAdapter;
public PopMovieFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main,container,false);
GridView gridView = (GridView) view.findViewById(R.id.gridview);
imageAdapter = new ImageAdapter(getActivity(),new ArrayList<String>());
gridView.setAdapter(imageAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("check","ok");
}
});
return inflater.inflate(R.layout.fragment_main, container, false);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void onStart() {
super.onStart();
updateMovies();
}
public void updateMovies() {
FetchMovieTask movieTask = new FetchMovieTask();
movieTask.execute();
}
public class FetchMovieTask extends AsyncTask<String, Void, String[]> {
final String LOG_TAG = FetchMovieTask.class.getSimpleName();
private String[] getMovieImageFromJson(String movieJsonStr)
throws JSONException {
ArrayList<String> movieResults = new ArrayList<>();
String posterUrl;
final String OWM_MOVIE_RESULTS = "results";
JSONObject jsonObject = new JSONObject(movieJsonStr);
if (jsonObject.has(OWM_MOVIE_RESULTS)) {
JSONArray movieArray = jsonObject.getJSONArray(OWM_MOVIE_RESULTS);
//JSONArray movieArray = jsonObject.getJSONArray(OWM_MOVIE_RESULTS);
for (int i = 0; i < movieArray.length(); i++) {
JSONObject movieObject = movieArray.getJSONObject(i);
posterUrl = movieObject.getString("poster_path");
movieResults.add(posterUrl);
Log.v(LOG_TAG, posterUrl);
}
for (String items : movieResults){
Log.v(LOG_TAG,items);
}
// return null;
}
return movieResults.toArray(new String[0]);
// Log.v(LOG_TAG,posterUrl);
}
#Override
protected String[] doInBackground(String... params) {
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
String movieJsonStr = null;
//parameters for api link will be here
try {
final String MOVIE_BASE_URL = "https://api.themoviedb.org/3/movie";
final String APPID_PARAM = "api_key";
final String CRITERIA_FOR_MOVIE_SELECTION_TOP = "top_rated";
final String CRITERIA_FOR_MOVIE_SELECTION_POPULAR = "popular";
Uri builtUri = Uri.parse(MOVIE_BASE_URL).buildUpon()
.appendPath(CRITERIA_FOR_MOVIE_SELECTION_TOP)
.appendQueryParameter(APPID_PARAM, BuildConfig.OPEN_MOVIEDB_API_KEY)
.build();
Log.v("TAG","BuiltURI" + builtUri.toString());
URL url = new URL(builtUri.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
// Read input stream into a String
InputStream inputstream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
if (inputstream == null) {
movieJsonStr = null;
}
reader = new BufferedReader(new InputStreamReader(inputstream));
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line + "\n");
}
if (buffer.length() == 0) {
movieJsonStr = null;
}
movieJsonStr = buffer.toString();
Log.v(LOG_TAG, "Movie Json String" + movieJsonStr);
} catch (IOException e) {
Log.e(LOG_TAG, "error here" + e);
movieJsonStr = null;
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e(LOG_TAG, "ErrorClosingStream", e);
}
}
}
try {
// here will be method call for JSon parsing.
String [] check_items = getMovieImageFromJson(movieJsonStr);
for (String items : check_items){
Log.v(LOG_TAG,items+"new");
}
return check_items;
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String[] result) {
if (result != null) {
for (String resultItems : result){
Log.v(LOG_TAG,resultItems+"GoodLuck");
final String PICTURE_BASE_URL = "http://image.tmdb.org/t/p/w185/";
final String PICTURE_URL_END = resultItems;
Uri builtUri = Uri.parse(PICTURE_BASE_URL).buildUpon()
.appendPath(PICTURE_URL_END.replace("/",""))
.build();
Log.v(LOG_TAG,resultItems+"GoodLuck"+builtUri.toString());
imageAdapter.setmresultItems(builtUri.toString());
}
}
}
}
}
class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<String> mresultItems;
public ImageAdapter(Context c,ArrayList<String> resultItems){
mContext = c;
mresultItems = resultItems;
}
public int getCount(){
// return mThumbsIds.length;
return 0;
}
public Object getItem(int position){
return null;
}
public long getItemId(int position){
return 0;
}
public void setmresultItems(String resultItems){
mresultItems.add(resultItems);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null){
// if it is not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85,85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
}else{
imageView = (ImageView) convertView;
}
//imageView.setImageResource(mThumbsIds[position]);
for(String picResultUrl : mresultItems){
Picasso.with(mContext).load(picResultUrl).into(imageView);
}
return imageView;
}
//references to our Images
//private Integer[] mThumbsIds ;
}**
You shouldn't have a for loop in the getView() method, it already gets called for each item in the list.
Be sure to return the correct count:
public int getCount(){
return mresultItems.size();
}
Then, use just the current position of the data source in getView():
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85,85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
}else{
imageView = (ImageView) convertView;
}
//modified:
String picUrl = mresultItems.get(position);
Picasso.with(mContext).load(picUrl).into(imageView);
}
return imageView;
}
Also, call notifyDataSetChanged() on the adapter in onPostExecute() after the data source of the adapter has been updated:
#Override
protected void onPostExecute(String[] result) {
if (result != null) {
for (String resultItems : result){
Log.v(LOG_TAG,resultItems+"GoodLuck");
final String PICTURE_BASE_URL = "http://image.tmdb.org/t/p/w185/";
final String PICTURE_URL_END = resultItems;
Uri builtUri = Uri.parse(PICTURE_BASE_URL).buildUpon()
.appendPath(PICTURE_URL_END.replace("/",""))
.build();
Log.v(LOG_TAG,resultItems+"GoodLuck"+builtUri.toString());
imageAdapter.setmresultItems(builtUri.toString());
}
//Add this here:
imageAdapter.notifyDataSetChanged();
}
}
I found that i was not returning view in onCreate method which was the root cause of blank screen.
Related
NOTE :
First of all before writing any thing. this is not a duplicate because if it is then why I will post this here. I didn't find any of the stackoverflow similar questions' answers helpful to me at all for 2 days straight.
THE PROBLEM :
I have an activity that takes two fields of data and then go to the next activity where it has a view pager and the activity opens 2 fragments the posts and the profile. the problem here is that when I go back to the first activity to input different data and go to the fragments the listview shows duplicate data.
I tried every possible solution but none works.
I tried to clear adapter.
I tried to pass empty adapter.
I tried more things in the life cycle of the fragment but nothing.
so please I need help. thanks in advance.
package psychrating.psychrating;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
/**
* Created by Ahmeed on 8/7/2017.
*/
public class PostsFragment extends Fragment {
static ListView posts_list;
Spinner list_order;
SearchView search;
String category, date, activity;
boolean get_data;
public static ArrayList<String> data = null;
static Context c;
transient ViewHolder holder;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
data = null;
activity = getArguments().getString("activity");
category = getArguments().getString("category");
date = getArguments().getString("date");
if (activity == "main") {
// get_data = true;
}else {
// get_data = true;
}
View view = inflater.inflate(R.layout.post_tab, container, false);
init(view);
posts_list.clearChoices();
if (searchResultses != null) {
searchResultses.clear();
searchResultses = null;
}
return view;
}
private void init(View view) {
posts_list = (ListView) view.findViewById(R.id.posts_list);
list_order = (Spinner) view.findViewById(R.id.list_order);
search = (SearchView) view.findViewById(R.id.search);
posts_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
holder = (ViewHolder) view.getTag();
Temp temp = new Temp();
temp.name = holder.name.getText().toString();
temp.highest = holder.highest.getText().toString();
temp.dname = holder.dname.getText().toString();
temp.date = holder.date.getText().toString();
temp.category = holder.category;
temp.sdesc = holder.sdesc;
temp.ddesc = holder.ddesc;
Intent i = new Intent(c, ProfileActivity.class);
i.putExtra("holder", temp);
startActivity(i);
}
});
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
c = context;
}
#Override
public void onResume() {
super.onResume();
searchResultses = new ArrayList<>();
new Server(this.getActivity(), "posts").execute(category, date);
}
public static final String TAG ="ahmed";
static void removeCommas() {
StringBuilder word = new StringBuilder();
for (int i = 0; i < data.size(); i++) {
for (int j = 0; j < data.get(i).length(); j++) {
char c = data.get(i).charAt(j);
if (c != ',') {
word.append(c);
}else {
words.add(word.toString());
word.delete(0, word.length());
}
}
}
}
#Override
public void onPause() {
super.onPause();
searchResultses = null;
adapter = null;
}
#Override
public void onDestroyView() {
super.onDestroyView();
}
static void addToClass() {
SearchResults s;
int offset = 0;
for (int j = 0; j < words.size(); j += 8) {
Log.d(TAG, String.valueOf(words.size()));
s = new SearchResults();
for (int i = 0; i < 8; i++) {
offset = 1;
s.add(words.get(i * offset));
}
offset += 1;
s.init();
searchResultses.add(s);
}
}
static ArrayList<SearchResults> searchResultses = null;
static ArrayList<String> words = new ArrayList<>();
static MyCustomBaseAdapter adapter = null;
public static void fillList() {
removeCommas();
addToClass();
ArrayList<SearchResults> empty = new ArrayList<>();
adapter = new MyCustomBaseAdapter(c, empty);
adapter = new MyCustomBaseAdapter(c, searchResultses);
posts_list.setAdapter(adapter);
}
}
NOTE:
the fillList is a func that is being called by the asynctask when it finished retrieving data . which use the data variable and remove commas from data and add words to searchResult class
package psychrating.psychrating;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.io.Serializable;
import java.util.ArrayList;
/**
* Created by Ahmeed on 8/10/2017.
*/
public class MyCustomBaseAdapter extends BaseAdapter {
private static ArrayList<SearchResults> searchArrayList = null;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results) {
super();
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(searchArrayList.get(position).getName());
holder.highest.setText(searchArrayList.get(position).getHighest());
holder.dname.setText(searchArrayList.get(position).getDName());
holder.date.setText(searchArrayList.get(position).getDate());
holder.category = searchArrayList.get(position).getCategory();
holder.sdesc = searchArrayList.get(position).getSdesc();
holder.ddesc = searchArrayList.get(position).getDdesc();
convertView.setTag(holder);
return convertView;
}
}
Server class
package psychrating.psychrating;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
/**
* Created by Ahmeed on 8/6/2017.
*/
public class Server extends AsyncTask<String, String, String> {
private Context context;
private ProgressDialog progressDialog;
private AlertDialog.Builder builder;
private String type;
private static ArrayList<String> data = null;
Server(Context context, String type) {
this.context = context;
this.type = type;
}
private void createPreDialog(String message) {
progressDialog = new ProgressDialog(context);
progressDialog.setMessage(message);
progressDialog.setCancelable(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressDialog.create();
}
progressDialog.show();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
createPreDialog("hold on");
}
#Override
protected String doInBackground(String... params) {
switch (type) {
case "login":
String personName = params[0];
String personEmail = params[1];
String id = params[2];
//
OutputStreamWriter outputStreamWriter = null;
BufferedWriter writer = null;
BufferedReader bufferedReader = null;
HttpURLConnection connection = null;
String line;
String result = null;
try {
URL url = new URL("http://192.168.1.64/blabla/sign_in.php");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setConnectTimeout(8000);
outputStreamWriter = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
writer = new BufferedWriter(outputStreamWriter);
String parameters = "name=" + personName + "&email=" + personEmail + "&id=" + id;
writer.write(parameters);
writer.flush();
if (connection.getResponseCode() == 200) {
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = bufferedReader.readLine()) != null) {
result = line;
}
} else {
result = "Server Error";
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (outputStreamWriter != null) {
outputStreamWriter.close();
}
if (connection != null) {
connection.disconnect();
}
if (bufferedReader != null) {
bufferedReader.close();
}
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
case "posts":
String category = params[0];
String date = params[1];
//
OutputStreamWriter outputStreamWriter1 = null;
BufferedWriter writer1 = null;
BufferedReader bufferedReader1 = null;
HttpURLConnection connection1 = null;
String line1 = "";
String result1 = null;
try {
URL url1 = new URL("http://192.168.1.64/blabla/posts.php");
connection1 = (HttpURLConnection) url1.openConnection();
connection1.setRequestMethod("POST");
connection1.setDoOutput(true);
connection1.setDoInput(true);
connection1.setConnectTimeout(8000);
outputStreamWriter1 = new OutputStreamWriter(connection1.getOutputStream(), "UTF-8");
writer1 = new BufferedWriter(outputStreamWriter1);
String parameters1 = "category="+category+"&date="+date;
writer1.write(parameters1);
writer1.flush();
data = new ArrayList<>();
if (connection1.getResponseCode() == 200) {
bufferedReader1 = new BufferedReader(new InputStreamReader(connection1.getInputStream()));
while ((line1 = bufferedReader1.readLine()) != null) {
data.add(line1);
}
} else {
result1 = "Server Error";
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (outputStreamWriter1 != null) {
outputStreamWriter1.close();
}
if (connection1 != null) {
connection1.disconnect();
}
if (bufferedReader1 != null) {
bufferedReader1.close();
}
if (writer1 != null) {
writer1.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result1;
}
return null;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressDialog.dismiss();
switch (type) {
case "login":
switch (s) {
case "Connect Error":
createDialog(s);
break;
case "Done":
Toast.makeText(context, s, Toast.LENGTH_LONG).show();
MainActivity.updateUI(true);
break;
case "Already Exist":
MainActivity.updateUI(true);
break;
case "Server Error":
createDialog(s);
break;
}
break;
case "posts":
if (data != null) {
PostsFragment.data = data;
PostsFragment.fillList();
data = null;
}
}
}
private void createDialog(String message) {
builder = new AlertDialog.Builder(context);
builder.setTitle("Error");
builder.setMessage(message);
builder.setCancelable(false);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create();
builder.show();
}
}
Your words in PostsFragment.java makes you element duplicate, In removeCommas() method first clears the words and then add the values to the words from data.
try this. searchResultses.clear(); at the start of addToClass()
static void addToClass() {
SearchResults s;
searchResultses.clear();
int offset = 0;
for (int j = 0; j < words.size(); j += 8) {
Log.d(TAG, String.valueOf(words.size()));
s = new SearchResults();
for (int i = 0; i < 8; i++) {
offset = 1;
s.add(words.get(i * offset));
}
offset += 1;
s.init();
searchResultses.add(s);
}
}
I want to show list of data seperated by pages that is first i want to show 5 details and then when user scrolls down then it loads 5 more by again calling the api now i have been able to show first 5 details but when scrolling it replaces previous 5 with new 5 details it is not adding data instead replacing it.
MainFile in which i want to show the data
package com.example.vinod.lcoportal;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
/**
* A simple {#link Fragment} subclass.
*/
public class StbDetailsFragment extends Fragment {
RecyclerView recycler_view_stb_details;
ArrayList<StbDetails> listitems_stb = new ArrayList<>();
String[] name = new String[50];
String[] address = new String[100];
String[] vc_stb = new String[100];
String[] city = new String[100];
String[] current_plan = new String[200];
String[] status = new String[50];
String[] csi = new String[300];
int currentpage = 0;
int pagesize = 5;
ProgressDialog pDialog;
JSONArray ja;
JSONObject jo;
String custcsi, custcity, custname, currentplan, custstatus, vc_no;
String stb_url = "http://lco.denonline.in/wapp/Service1.svc/Dashboard";
public StbDetailsFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_stb_details, container, false);
currentpage = currentpage + 1;
GetStb getStb= new GetStb(currentpage, pagesize);
getStb.execute(stb_url);
return view;
}
public class MyAdapterStb extends RecyclerView.Adapter<MyAdapterStb.MyViewHolderStb> {
private ArrayList<StbDetails> list;
public MyAdapterStb(ArrayList<StbDetails> Data) {
list = Data;
}
#Override
public MyViewHolderStb onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.stb_details_cardview, parent, false);
MyViewHolderStb holder = new MyViewHolderStb(view);
return holder;
}
#Override
public void onBindViewHolder(final MyViewHolderStb holder, int position) {
holder.cust_name.setText(list.get(position).getName());
holder.cust_address.setText(list.get(position).getAddress());
holder.cust_vc.setText(list.get(position).getVc_stb_no());
holder.cust_city.setText(list.get(position).getCity());
holder.cust_plan.setText(list.get(position).getCurrentPlan());
holder.cust_status.setText(list.get(position).getStatus());
// holder.events_imageview.setImageResource(list.get(position).getImageResourceId());
// holder.events_imageview.setTag(list.get(position).getImageResourceId());
// Glide.with(getActivity()).load(list.get(position).getImageResourceId_notices()).into(holder.notices_imageview);
}
#Override
public int getItemCount() {
return list.size();
}
public class MyViewHolderStb extends RecyclerView.ViewHolder {
TextView cust_name, cust_address, cust_vc, cust_city, cust_plan, cust_status ;
public MyViewHolderStb(View v) {
super(v);
cust_name = (TextView) v.findViewById(R.id.name_stb_details);
cust_address = (TextView) v.findViewById(R.id.address_stb_details);
cust_vc = (TextView) v.findViewById(R.id.vc_stb_no_stb_details);
cust_city = (TextView) v.findViewById(R.id.city_stb_details);
cust_plan = (TextView) v.findViewById(R.id.current_plan_stb_details);
cust_status = (TextView) v.findViewById(R.id.status_stb_details);
// v.setOnClickListener(new View.OnClickListener() {
// #Override
// public void onClick(View v) {
// Intent i = new Intent(getActivity(),NoticesViewActivity.class);
// i.putExtra("notice_url",pdf[getAdapterPosition()]);
// i.putExtra("notice_title",title_notices[getAdapterPosition()]);
// startActivity(i);
// }
// });
}
}
}
public void initializeList() {
listitems_stb.clear();
for (int i = 0; i < ja.length(); i++) {
StbDetails item = new StbDetails();
item.setName(name[i]);
item.setAddress(address[i]);
item.setVc_stb_no(vc_stb[i]);
item.setCity(city[i]);
item.setCurrentPlan(current_plan[i]);
item.setStatus(status[i]);
listitems_stb.add(item);
}
}
public class GetStb extends AsyncTask<String,String,String> {
HttpURLConnection httpURLConnection;
int CurrentPage, PageSize;
public GetStb(int currentpage, int pagesize) {
CurrentPage = currentpage;
PageSize = pagesize;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Fetching Data...Please Wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//pDialog.show();
// progress_dialog.setVisibility(View.VISIBLE);
}
#Override
protected String doInBackground(String... params) {
try {
URL url = new URL(params[0]);
Log.d("DoInBackground:URL", url.toString());
//Send Post Data request
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.addRequestProperty("api_key", "XBoGycClZkJrXDVphgpN5c9Bb82fcKQ4");
httpURLConnection.addRequestProperty("gulco", "fe96632f-5173-e611-942d-005056bb1e58");
httpURLConnection.addRequestProperty("currentpage", String.valueOf(CurrentPage));
httpURLConnection.addRequestProperty("pagesize", String.valueOf(PageSize));
//)httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
//Get the Server Response
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String response = "";
String line = "";
while ((line = bufferedReader.readLine()) != null) {
response += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
Log.d("DoInBackground", "Response:" + response);
return response;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String response) {
GridLayoutManager MyLayoutManager = new GridLayoutManager(getActivity(),1);
MyLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
recycler_view_stb_details = (RecyclerView) getActivity().findViewById(R.id.recycler_view_stb_details);
recycler_view_stb_details.setHasFixedSize(true);
try {
ja = new JSONArray(response);
//ja = jo.getJSONArray("notices");
//images = new String[ja.length()];
//title = new String[ja.length()];
for (int i=0;i<ja.length();i++) {
JSONObject json = ja.getJSONObject(i);
custcsi = json.getString("CSI");
custcity = json.getString("City");
custname = json.getString("CustName");
currentplan = json.getString("Plan");
custstatus = json.getString("Status");
vc_no = json.getString("VCNO");
name[i] = custname;
csi[i] = custcsi;
city[i] = custcity;
current_plan[i] = currentplan;
vc_stb[i] = vc_no;
status[i] = custstatus;
initializeList();
}
} catch (Exception e) {
e.printStackTrace();
}
//progress_dialog.setVisibility(View.GONE);
//pDialog.dismiss();
if (listitems_stb.size() > 0 & recycler_view_stb_details != null) {
recycler_view_stb_details.setAdapter(new MyAdapterStb(listitems_stb));
}
recycler_view_stb_details.setLayoutManager(MyLayoutManager);
//pDialog.dismiss();
}
}
}
I think your problem is that every time in the public void initializeList() you call first of all listitems_stb.clear(); so your list will be cleared every time and you will lose all the previous data.
So if you wanna add other elements to the list you shouldn't clear it. Just try to delete listitems_stb.clear();.
Then for pagination see this answer here.
Hope this helps
I am trying to make an app where I want my app, on launch, to display a grid of popular movie posters. The movie posters are downloaded from TheMovieDataBase API. I then use Picasso to load the images. For the GridView I am also using a custom adapter. I am not able to understand how to do it. Here is what I have done up till now
MovieFragment.java
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MovieFragment extends Fragment {
//ArrayAdapter<String> mMovieAdapter;
String[]movieId,movieTitle,movieOverview,
movieReleaseDate,
moviePosterPath,movieVoteAverage;
public MovieFragment() {
}
MovieAdapter mMovieAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
mMovieAdapter = new MovieAdapter(getActivity());
GridView listView = (GridView) rootView.findViewById(R.id.gridView);
listView.setAdapter(mMovieAdapter);
updateMovie();
return rootView;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.menu_fragment, menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_refresh) {
updateMovie();
return true;
}
return super.onOptionsItemSelected(item);
}
private void updateMovie() {
FetchMovieTask movieTask = new FetchMovieTask();
movieTask.execute();
}
class FetchMovieTask extends AsyncTask<Void, Void, List<String>> {
private final String LOG_TAG = FetchMovieTask.class.getSimpleName();
#Override
protected List<String> doInBackground(Void... params) {
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
// Will contain the raw JSON response as a string.
String movieJsonStr = null;
try {
URL url = new URL("http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=c20129fdf73b5df3ab44548ad7f73586");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
// Read the input stream into a String
InputStream inputStream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
if (inputStream == null) {
// Nothing to do.
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line + "\n");
}
if (buffer.length() == 0) {
// Stream was empty. No point in parsing.
return null;
}
movieJsonStr = buffer.toString();
} catch (IOException e) {
Log.e(LOG_TAG, "Error ", e);
return null;
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e(LOG_TAG, "Error closing stream", e);
}
}
}
try {
return getMovieDataFromJson(movieJsonStr);
} catch (JSONException j) {
Log.e(LOG_TAG, "JSON Error", j);
}
return null;
}
private List<String> getMovieDataFromJson(String forecastJsonStr)
throws JSONException {
JSONObject movieJson = new JSONObject(forecastJsonStr);
JSONArray movieArray = movieJson.getJSONArray("results");
List<String> urls = new ArrayList<>();
for (int i = 0; i < movieArray.length(); i++) {
JSONObject movie = movieArray.getJSONObject(i);
urls.add("http://image.tmdb.org/t/p/w185" + movie.getString("poster_path"));
}
return urls;
}
#Override
protected void onPostExecute(List<String> strings) {
mMovieAdapter.replace(strings);
}
}
class MovieAdapter extends BaseAdapter {
private final String LOG_TAG = MovieAdapter.class.getSimpleName();
private final Context context;
private final List<String> urls = new ArrayList<String>();
public MovieAdapter(Context context) {
this.context = context;
Collections.addAll(urls, moviePosterPath);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = new ImageView(context);
}
ImageView imageView = (ImageView) convertView;
String url = getItem(position);
Log.e(LOG_TAG," URL "+url);
Picasso.with(context).load(url).into(imageView);
return convertView;
}
#Override
public int getCount() {
return urls.size();
}
#Override
public String getItem(int position) {
return urls.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public void replace(List<String> urls) {
this.urls.clear();
this.urls.addAll(urls);
notifyDataSetChanged();
}
}
}
When I run this code it shows a NullPointerException and a RuntimeException
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.codesetters.verader/com.codesetters.verader.MainActivity}: java.lang.NullPointerException atandroid.app.ActivityThreadperformLaunchActivity(ActivityThread.java:2404)
Caused by: java.lang.NullPointerException atjava.util.Collections.addAll(Collections.java:2582)
How can I resolve them?
Please Help
You're getting this error because you've used moviePosterPath here :
Collections.addAll(urls, moviePosterPath);
but you've not initialized it anywhere. Initialize it with some value and it should solve the error.
The null pointer could be because the String array moviePosterPath is not initialized. and you are ussing it in Collections.addAll
This is how to initialize an array. Anyway I recommend you to use ArrayList
String[] moviePosterPath = new String[N];
I have been trying too hard to get around this problom, when I tap the refresh button in my app, the images doesn't load on the screen.
This the DataFragment file, when i build this app there are no errors.
package com.example.popularmovis;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.os.AsyncTask;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.jar.JarException;
/**
* A placeholder fragment containing a simple view.
*/
public class DataFragment extends Fragment {
public ImageAdapter display;
public DataFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add this line in order for this fragment to handle menu events.
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.datafragment_menu, menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_refresh) {
FetchMovieData movieData = new FetchMovieData();
movieData.execute();
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
display = new ImageAdapter(rootView.getContext());
GridView gridView = (GridView) rootView.findViewById(R.id.gridView_movies);
gridView.setAdapter(display); // uses the view to get the context instead of getActivity().
return rootView;
}
public class FetchMovieData extends AsyncTask<Void, Void, String[]>{
private final String LOG_TAG = FetchMovieData.class.getSimpleName();
private String[] extractdisplayFromJason(String jasnData)
throws JSONException{
//These jason display need to be extracted
final String movie_results = "results";
final String movie_poster = "poster_path";
JSONObject movieData = new JSONObject(jasnData);
JSONArray movieArray = movieData.getJSONArray(movie_results);
String[] posterAddreess = new String[movieArray.length()];
//Fill ther posterAddreess with the URL to display
for(int j=0; j < movieArray.length(); j++){
String posterPath;
JSONObject movieArrayItem = movieArray.getJSONObject(j);
posterPath = movieArrayItem.getString(movie_poster);
posterAddreess[j] = "http://image.tmdb.org/t/p/w185/" + posterPath;
}
for (String s : posterAddreess) {
Log.v(LOG_TAG, "Thumbnail Links: " + s);
}
return posterAddreess;
}
#Override
protected String[] doInBackground(Void... params) {
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
String JsonData = null;
String country = "US";
String rating = "R";
String sort = "popularity.desc";
String apiKey = "";
//building the URL for the movie DB
try {
//building the URL for the movie DB
final String MovieDatabaseUrl = "https://api.themoviedb.org/3/discover/movie?";
final String Country_for_release = "certification_country";
final String Rating = "certification";
final String Sorting_Order = "sort_by";
final String Api_Id = "api_key";
Uri buildUri = Uri.parse(MovieDatabaseUrl).buildUpon()
.appendQueryParameter(Country_for_release, country)
.appendQueryParameter(Rating, rating)
.appendQueryParameter(Sorting_Order, sort)
.appendQueryParameter(Api_Id, apiKey)
.build();
//Converting URI to URL
URL url = new URL(buildUri.toString());
Log.v(LOG_TAG, "Built URI = "+ buildUri.toString());
//Create the request to the Movie Database
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
//Read the input from the database into string
InputStream inputStream = urlConnection.getInputStream();
//StringBuffer for string Manipulation
StringBuffer buffer = new StringBuffer();
if (inputStream == null) {
// Nothing to do.
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
// But it does make debugging a *lot* easier if you print out the completed
// buffer for debugging.
buffer.append(line + "\n");
}
if (buffer.length() == 0) {
// Stream was empty. No point in parsing.
return null;
}
JsonData = buffer.toString();
Log.v(LOG_TAG,"Forecaast Jason String" + JsonData );
} catch (IOException e) {
// If the code didn't successfully get the weather data, there's no point in attemping
// to parse it.
return null;
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e(LOG_TAG, "Error closing stream", e);
}
}
try {
return extractdisplayFromJason(JsonData);
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(String[] posterAddreess) {
for (String poster : posterAddreess) {
display.addItem(poster);
}
}
}
}
This the ImageAdapter code
package com.example.popularmovis;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.example.popularmovis.R;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ArrayList<String> images = new ArrayList<String>();
public ImageAdapter(Context c){
mContext = c;
}
#Override
public int getCount(){
return images.size();
}
#Override
public Object getItem(int position){
return images.get(position);
}
public long getItemId(int position){
return 0;
}
public View getView(int position, View convertView, ViewGroup parent){
ImageView imageview;
if (convertView == null){
imageview = new ImageView(mContext);
imageview.setPadding(0, 0, 0, 0);
//imageview.setLayoutParams(new GridLayout.MarginLayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
imageview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageview.setAdjustViewBounds(true);
} else {
imageview = (ImageView) convertView;
}
Picasso.with(mContext).load(images.get(position)).placeholder(R.mipmap.ic_launcher).into(imageview);
return imageview;
}
/*
Custom methods
*/
public void addItem(String url){
images.add(url);
}
public void clearItems() {
images.clear();
}
}
When you use this in your onCreate method like this, it means that the object is local to the method and can't be use in other methods.
ImageAdapter display = new ImageAdapter(rootView.getContext());
First create a global class member variable
private ImageAdapter display;
then inside your onCreate method do this
display = new ImageAdapter(rootView.getContext());
Currently I am developing a Popular Movies app by udacity and stuck at loading images from the MovieDb api. I have also took reference from this thread Picasso Images are not loading in Gridview Android but no use.
Here is my fragment file:
package com.akshitjain.popularmovies;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* A placeholder fragment containing a simple view.
*/
public class MainActivityFragment extends Fragment {
ImageAdapter mMoviesAdapter;
public MainActivityFragment() {
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
setHasOptionsMenu(true);
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
GridView gridview = (GridView) rootView.findViewById(R.id.grid_view_movies);
mMoviesAdapter = new ImageAdapter(getActivity());
gridview.setAdapter(mMoviesAdapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Toast.makeText(getActivity(), "" + position,
Toast.LENGTH_SHORT).show();
}
});
return rootView;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_mainfragment,menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_refresh){
String sortOrder = "popularity.desc";
new FetchMoviesTask().execute(sortOrder);
return true;
}
return super.onOptionsItemSelected(item);
}
public class FetchMoviesTask extends AsyncTask<String, Void, String[]> {
private final String LOG_TAG = FetchMoviesTask.class.getSimpleName();
private String[] getMoviesDataFromJson(String moviesJsonStr)
throws JSONException {
final String TMDB_RESULTS = "results";
final String TMDB_POSTER = "poster_path";
JSONObject moviesJson = new JSONObject(moviesJsonStr);
JSONArray moviesArray = moviesJson.getJSONArray(TMDB_RESULTS);
String[] resultStrs = new String[moviesArray.length()];
for(int i=0;i<moviesArray.length();++i) {
JSONObject movieObject = moviesArray.getJSONObject(i);
resultStrs[i] = movieObject.getString(TMDB_POSTER);
}
return resultStrs;
}
#Override
protected String[] doInBackground(String... params) {
// These two need to be declared outside the try/catch
// so that they can be closed in the finally block.
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
// Will contain the raw JSON response as a string.
String moviesJsonStr;
String apiKey = BuildConfig.THE_MOVIE_DB_API_KEY;
try {
// Construct the URL for the TheMovieDb query
// Possible parameters are available at TheMovieDb API page
final String MOVIES_BASE_URL = "http://api.themoviedb.org/3/discover/movie?";
final String SORT_PARAM = "sort_by";
final String API_KEY = "api_key";
Uri builtUri = Uri.parse(MOVIES_BASE_URL).buildUpon()
.appendQueryParameter(SORT_PARAM,params[0])
.appendQueryParameter(API_KEY,apiKey)
.build();
URL url = new URL(builtUri.toString());
Log.v(LOG_TAG,"BuiltUri: " + builtUri.toString());
// Create the request to TheMovieDb, and open the connection
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
// Read the input stream into a String
InputStream inputStream = urlConnection.getInputStream();
StringBuilder buffer = new StringBuilder();
if (inputStream == null) {
// Nothing to do.
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
// But it does make debugging a *lot* easier if you print out the completed
// buffer for debugging.
buffer.append(line).append("\n");
}
if (buffer.length() == 0) {
// Stream was empty. No point in parsing.
return null;
}
moviesJsonStr = buffer.toString();
Log.v(LOG_TAG,"Movies Json String: " + moviesJsonStr);
} catch (IOException e) {
Log.e("MainActivityFragment", "Error ", e);
// If the code didn't successfully get the weather data, there's no point in attempting
// to parse it.
return null;
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e("MainActivityFragment", "Error closing stream", e);
}
}
}
try{
return getMoviesDataFromJson(moviesJsonStr);
}catch (JSONException e){
Log.e(LOG_TAG,e.getMessage(),e);
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String[] strings) {
if(strings != null){
mMoviesAdapter.clear();
for(String moviesStr:strings){
mMoviesAdapter.add(moviesStr);
}
}
mMoviesAdapter.notifyDataSetChanged();
super.onPostExecute(strings);
}
}
}
Here is my custom adapter file:
package com.akshitjain.popularmovies;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
public class ImageAdapter extends BaseAdapter {
private final String LOG_TAG = ImageAdapter.class.getSimpleName();
private Context mContext;
List<String> list = new ArrayList<>();
public ImageAdapter(Context c) {
this.mContext = c;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.grid_item_movies, parent, false);
}
final String POSTER_BASE_URL = " http://image.tmdb.org/t/p/";
final String POSTER_SIZE = "w185";
ImageView moviePoster = (ImageView) convertView.findViewById(R.id.grid_item_movie_image);
final String POSTER_FINAL_URL = POSTER_BASE_URL + POSTER_SIZE + list.get(position);
Log.v(LOG_TAG,"Poster Urls: " + POSTER_FINAL_URL);
Picasso.with(mContext).load(POSTER_FINAL_URL).into(moviePoster);
return convertView;
}
public void add(String s) {
list.add(s);
}
public void clear() {
list.clear();
}
}
There is no error in the code. App runs successfully. But images are not loading.
final String POSTER_BASE_URL = " http://image.tmdb.org/t/p/";
The space at the beginning of the string was the issue. Picasso will try and load url with space at front.
So String.trim() will remove the space from the beginning as well as the end of a String.
Picasso.with(mContext).load(POSTER_FINAL_URL.trim()).into(moviePoster)