Picasso not showing more then one image in a adapter - android

I am using a adapter for homework and at that adaper there is also a adapter which contains images and i am getting urls from firebase database here i have code for more information.
what product.getUrl is actually containing
D/ADAPTER_IMAGE: [https://firebasestorage.googleapis.com/v0/b/ngf-connection.appspot.com/o/uploads%2FBtech%20CSE%20I%2F917838245010_status_66703835b57940eb8812f50c09aacbd1.jpg?alt=media&token=b9de8228-36f4-496a-9ca5-dc0640f2eb9e
2020-04-08 18:13:10.331 12057-12057/com.ngfcet.ngfconnection D/ADAPTER_IMAGE: https://firebasestorage.googleapis.com/v0/b/ngf-connection.appspot.com/o/uploads%2FBtech%20CSE%20I%2F917248800852_status_200b86ad9f0d43e8aab65037b1588f32.jpg?alt=media&token=47b2f7ed-3cf1-4aea-9883-0f552e24754e
2020-04-08 18:13:10.344 12057-12057/com.ngfcet.ngfconnection D/ADAPTER_IMAGE: https://firebasestorage.googleapis.com/v0/b/ngf-connection.appspot.com/o/uploads%2FBtech%20CSE%20I%2F918400606848_status_cdad13e789b049fcbe4c396cf7170fa6.jpg?alt=media&token=fbb825bf-1aab-4056-b12b-01ca458a21a5
2020-04-08 18:13:10.355 12057-12057/com.ngfcet.ngfconnection D/ADAPTER_IMAGE: https://firebasestorage.googleapis.com/v0/b/ngf-connection.appspot.com/o/uploads%2FBtech%20CSE%20I%2FIMG-20200408-WA0003.jpg?alt=media&token=fb16dd18-26aa-4d28-86ea-de32dbbdbeb4]
Adapter 1: Main Line is with comment //setting another adaper from here
import android.content.Context;
import android.net.Uri;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.database.ValueEventListener;
import com.ngfcet.ngfconnection.R;
import com.ngfcet.ngfconnection.SendHomeworkActivity;
import com.ngfcet.ngfconnection.Util.CoreHelper;
import com.ngfcet.ngfconnection.models.HomeworkStudents;
import com.ngfcet.ngfconnection.models.ImageHomeworkModel;
import com.ngfcet.ngfconnection.models.ImagesModel;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.ProductViewHolder> {
//this context we will use to inflate the layout
private Context mCtx;
String dateValue, datePrevValue;
URI myUri;
//we are storing all the products in a list
private List<HomeworkStudents> productList;
private static SingleClickListener sClickListener;
ImagesHomeworkAdapter adapter;
List<ImageHomeworkModel> imagesList;
CoreHelper coreHelper;
private static int sSelected = -1;
//getting the context and product list with constructor
public HomeworkAdapter(Context mCtx, List<HomeworkStudents> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
#Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//inflating and returning our view holder
LayoutInflater inflater = LayoutInflater.from(mCtx);
View view = inflater.inflate(R.layout.recycler_home_work, null);
return new ProductViewHolder(view);
}
#Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
//getting the product of the specified position
final HomeworkStudents product = productList.get(position);
//binding the data with the viewholder views
holder.textViewDescription.setText(product.getDescription());
holder.textViewSubject.setText(product.getSubject());
coreHelper = new CoreHelper(mCtx);
imagesList = new ArrayList<>();
adapter = new ImagesHomeworkAdapter(mCtx, imagesList);
GridLayoutManager gridLayoutManager = new GridLayoutManager(mCtx, 4);
holder.recyclerViewHomeWorkImages.setHasFixedSize(true);
holder.recyclerViewHomeWorkImages.setLayoutManager(gridLayoutManager);
holder.recyclerViewHomeWorkImages.setAdapter(adapter);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy & kk:mm:ss");
Date sourceDate = null;
try {
sourceDate = dateFormat.parse(product.getDateTime());
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat targetFormat = new SimpleDateFormat("kk:mm");
String targetdatevalue = targetFormat.format(sourceDate);
holder.textViewDateTime.setText(targetdatevalue);
SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy & kk:mm:ss");
Date dt1 = null;
try {
dt1 = format1.parse(product.getDateTime());
} catch (ParseException e) {
e.printStackTrace();
}
DateFormat format2 = new SimpleDateFormat("EEEE");
String finalDay = format2.format(dt1);
holder.tvDayHomework.setText(finalDay);
Date realDate = null;
try {
realDate = dateFormat.parse(product.getDateTime());
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat dateHomework = new SimpleDateFormat("dd MMM yyyy");
dateValue = dateHomework.format(realDate);
holder.tvDateHomework.setText(dateValue);
if (sSelected == position) {
holder.textViewDescription.setSingleLine(false);
if (!product.getAttachments().equals("")) {
String urls = product.getAttachments();
String[] urlsArray = urls.split(",");
for (String url : urlsArray) {
Log.d("IMAGE_URL", url);
holder.recyclerViewHomeWorkImages.setVisibility(View.VISIBLE);
holder.imgButtonDownload.setVisibility(View.VISIBLE);
imagesList.add(new ImageHomeworkModel(url, "Name")); // setting another adapter from here
}
}
// holder.mTextView.setBackgroundColor(Color.parseColor("#CBEEEEEE"));
// holder.mTextView.setTextColor(Color.parseColor("#FBC02D"));
} else {
holder.textViewDescription.setSingleLine(true);
holder.imgButtonDownload.setVisibility(View.GONE);
holder.recyclerViewHomeWorkImages.setVisibility(View.GONE);
// holder.mTextView.setBackgroundColor(Color.parseColor("#FFFFFF"));
// holder.mTextView.setTextColor(Color.parseColor("#000000"));
}
holder.imgButtonDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (!product.getAttachments().equals("")) {
StringTokenizer tokenizer = new StringTokenizer(product.getAttachments(), ",");
while (tokenizer.hasMoreTokens()) {
// System.out.println(tokenizer.nextToken());
Log.d("Attachment Token", tokenizer.nextToken());
}
// Toast.makeText(mCtx, product.getAttachments(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mCtx, "Nothing to download", Toast.LENGTH_SHORT).show();
}
}
});
if (position == 0) {
holder.llDayDateHomework.setVisibility(View.VISIBLE);
} else {
HomeworkStudents previous = productList.get(position - 1);
Date previoudDate = null;
Date otherDate = null;
try {
previoudDate = dateFormat.parse(previous.getDateTime());
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat previousDateHomework = new SimpleDateFormat("dd MMM yyyy");
String previousDateValue = previousDateHomework.format(previoudDate);
try {
otherDate = dateFormat.parse(product.getDateTime());
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat otherDateHomework = new SimpleDateFormat("dd MMM yyyy");
String otherDateValue = otherDateHomework.format(otherDate);
if (previousDateValue.equals(otherDateValue)) {
holder.llDayDateHomework.setVisibility(View.GONE);
} else {
holder.llDayDateHomework.setVisibility(View.VISIBLE);
}
}
}
#Override
public int getItemCount() {
return productList.size();
}
class ProductViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView textViewDescription, textViewSubject, textViewDateTime, tvDayHomework, tvDateHomework;
LinearLayout llDayDateHomework;
CardView cardViewHomework;
ImageButton imgButtonDownload;
RecyclerView recyclerViewHomeWorkImages;
public ProductViewHolder(View itemView) {
super(itemView);
textViewDescription = itemView.findViewById(R.id.tvTitleHomework);
textViewSubject = itemView.findViewById(R.id.tvSubjectHomework);
textViewDateTime = itemView.findViewById(R.id.tvDateTimeHomework);
tvDayHomework = itemView.findViewById(R.id.tvDayHomework);
tvDateHomework = itemView.findViewById(R.id.tvDateHomework);
llDayDateHomework = itemView.findViewById(R.id.llDayDateHomework);
cardViewHomework = itemView.findViewById(R.id.cardViewHomework);
imgButtonDownload = itemView.findViewById(R.id.imgButtonDownload);
recyclerViewHomeWorkImages = itemView.findViewById(R.id.recyclerViewHomeWorkImages);
cardViewHomework.setOnClickListener(this);
}
#Override
public void onClick(View view) {
sSelected = getAdapterPosition();
sClickListener.onItemClickListener(getAdapterPosition(), view);
}
}
public void selectedItem() {
notifyDataSetChanged();
}
public void setOnItemClickListener(SingleClickListener clickListener) {
sClickListener = clickListener;
}
public interface SingleClickListener {
void onItemClickListener(int position, View view);
}
}
Adapter 2: Main line is with comment //Setting image with picasso
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.ngfcet.ngfconnection.R;
import com.ngfcet.ngfconnection.models.ImageHomeworkModel;
import com.squareup.picasso.Picasso;
import java.util.List;
public class ImagesHomeworkAdapter extends RecyclerView.Adapter<ImagesHomeworkAdapter.ImageViewHolder> {
Context context;
List<ImageHomeworkModel> imagesList;
public ImagesHomeworkAdapter(Context context, List<ImageHomeworkModel> imagesList) {
this.context = context;
this.imagesList = imagesList;
}
#NonNull
#Override
public ImagesHomeworkAdapter.ImageViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.picked_img_layout, parent, false);
return new ImagesHomeworkAdapter.ImageViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ImagesHomeworkAdapter.ImageViewHolder holder, final int position) {
ImageHomeworkModel product = imagesList.get(position);
holder.btnRemove.setVisibility(View.GONE);
Picasso.with(context).load(product.getUrls()).into(holder.imgSetData); //Setting image with picasso
Log.d("ADAPTER_IMAGE_URL", product.getUrls());
if (holder.imgSetData.getDrawable() == null) {
holder.imgSetData.setImageResource(R.drawable.ic_pdf);
}
}
#Override
public int getItemCount() {
return imagesList.size();
}
class ImageViewHolder extends RecyclerView.ViewHolder {
ImageView btnRemove, imgSetData;
public ImageViewHolder(#NonNull View itemView) {
super(itemView);
btnRemove = itemView.findViewById(R.id.imgDeleteSelectedImage);
imgSetData = itemView.findViewById(R.id.imgSetData);
}
}
}
Model Class
public class ImageHomeworkModel {
private String Urls;
private String fileName;
public ImageHomeworkModel(String urls, String fileName) {
Urls = urls;
this.fileName = fileName;
}
public ImageHomeworkModel(String[] urlsArray, String name) {
}
public String getUrls() {
return Urls;
}
public void setUrls(String urls) {
Urls = urls;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
}
Please help me to solve my issue picasso not showing image even logcan isn't showing anything

Hey i got the answer of my question problem is square bracets
url containg [ ] in starting and end but
replace is not working
I'm doing
product.getUrls().replace("[", "");
product.getUrls().replace("]", "");
but it's not replacing sqaure btackets.

Related

This error is coming while doing intent Cannot resolve method 'putExtra(java.lang.String, <lambda parameter>)'?

I am getting this error when doing intent. I don't know why it is coming. I need to go to the fragment to activity. I need to go to the next activity with the api in this application. I have tried many times and I am not getting the answer.**Cannot resolve method 'putExtra(java.lang.String, <lambda parameter>)'**I have given the image below How to do fragment to activity intent i am new android devloper
package com.kannada.newspaper.india.utils;
import static com.kannada.newspaper.india.Constant.EXTRA_OBJC;
import static com.kannada.newspaper.india.Constant.getApiUrl;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import com.kannada.newspaper.india.AppConfig;
import com.kannada.newspaper.india.Constant;
import com.kannada.newspaper.india.MainActivity;
import com.kannada.newspaper.india.R;
import com.kannada.newspaper.india.activities.ActivityCategoryDetail;
import com.kannada.newspaper.india.adapters.GalleryAdapter;
import com.kannada.newspaper.india.model.Category;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class FragmentCategory extends Fragment {
private Call<CallbackHome> callbackCall = null;
SharedPref sharedPref;
private View root_view;
public static final String EXTRA_OBJC = "key.EXTRA_OBJC";
private GalleryAdapter adapterCategory;
private GridView gridView;
private List<Category> mensWears;
private GalleryAdapter adapter;
private Category category;
public FragmentCategory() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,
Bundle savedInstanceState) {
requestAction();
category = (Category) getActivity().getIntent().getSerializableExtra(Constant.EXTRA_OBJC);
// Inflate the layout for this fragment
root_view = inflater.inflate(R.layout.fragment_phones,container,false);
((TextView) root_view.findViewById(R.id.txt_title_category)).setText(getResources().getString(R.string.home_title_category));
return root_view;
}
private void requestAction() {
new Handler().postDelayed(this::requestHomeData, Constant.DELAY_TIME);
}
private void requestHomeData() {
this.callbackCall = RestAdapter.createAPI(getApiUrl).getHome(AppConfig.REST_API_KEY);
this.callbackCall.enqueue(new Callback<CallbackHome>() {
public void onResponse(Call<CallbackHome> call, Response<CallbackHome> response) {
CallbackHome responseHome = response.body();
if (responseHome == null || !responseHome.status.equals("ok")) {
return;
}
displayData(responseHome);
}
public void onFailure(Call<CallbackHome> call, Throwable th) {
Log.e("onFailure", th.getMessage());
if (!call.isCanceled()) {
}
}
});
}
private void displayData(CallbackHome responseHome) {
displayCategory(responseHome.category);
}
private void displayCategory(List<Category> list) {
GridView gridView = (GridView) root_view.findViewById(R.id.gridHolder);
adapterCategory = new GalleryAdapter(getActivity(), list);
gridView.setAdapter(adapterCategory);
GalleryAdapter.setOnItemClickListener((v, obj, position) -> {
Intent intent = new Intent(getActivity(), ActivityCategoryDetail.class);
intent.putExtra(EXTRA_OBJC, obj);
startActivity(intent);
});
LinearLayout lyt_category = root_view.findViewById(R.id.lyt_category);
if (list.size() > 0) {
// lyt_category.setVisibility(View.VISIBLE);
} else {
// lyt_category.setVisibility(View.GONE);
}
}
}
GalleryAdapter adapter
public class GalleryAdapter extends BaseAdapter {
private Context context;
private List<Category> mensWears;
public GalleryAdapter(Context context, List<Category> mensWears) {
this.context = context;
this.mensWears = mensWears;
}
public static void setOnItemClickListener(Object o) {
}
#Override
public int getCount() {
return mensWears.size();
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i,View view,ViewGroup viewGroup) {
final Category mensWear = mensWears.get(i);
if (view == null) {
final LayoutInflater layoutInflater = LayoutInflater.from(context);
view = layoutInflater.inflate(R.layout.custom_gallery_layout, null);
}
//For text
TextView prdId = view.findViewById(R.id.category_name);
ImageView imageView = view.findViewById(R.id.category_image);
// prdId.setText(prdId.toString());
Picasso.get()
.load(getApiUrl + "/upload/category/" + mensWears.get(i).category_image())
.placeholder(R.drawable.ic_thumbnail)
.into(imageView);
prdId.setText(mensWears.get(i).getItemName());
// //For images
// final ImageView imageView = view.findViewById(R.id.name);
// if(!TextUtils.isEmpty(mensWear.getItemName())){
//
//// Picasso.with(context).load(imageUrlFromServer+mensWear.category_image())
//// .into(imageView);
return view;
}
}
You cannot put Object type in putExtra , it has to be either serailized, string, double and other primitive type.
You can do like this:
Category category = (Category)adapter.getItemAtPosition(pos);
or this should also work:
Category category = (Category) obj
then,
intent.putExtra(EXTRA_OBJC,category)
Note: Your Category class should implement parcelable or serilizable to be passed as an intent.
public class Category implements Serializable {
..........}

Array list size always 0, even after add data to it

I want to display what my array list value is. So, I want to loop with the size of array list as the limit. But after I add some value through a function, and want to get the size of it, it always 0. I still newbie in android programming. I had search in google, but still confused and not understand what the problem is. Thanks for you guys help
I had tried to set through global variable, but it's not work
Here is my activity file
package bobby.irawan.aticket;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;
public class DetailPromoActivity extends AppCompatActivity {
private ListView listView;
private TextView nama_detail_promo_tv;
private String nama_detail_promo;
private DetailPromoAdapter adapter;
private int counter_header=0, counter_promo = 0;
private View layout_kupon;
private int id_link_promo;
private RequestQueue requestQueue;
private String url = "192.168.11.134:8000";
private TextView header_promo, kupon_promo, notif_promo;
private ArrayList<DetailPromo> detailPromos;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_promo);
View view = findViewById(R.id.layout_kupon);
header_promo = view.findViewById(R.id.header_promo_tv);
kupon_promo = view.findViewById(R.id.kode_promo_tv);
id_link_promo = (int) getIntent().getSerializableExtra("id_promo");
nama_detail_promo = (String) getIntent().getSerializableExtra("nama_promo");
String nama_ota = (String) getIntent().getSerializableExtra("nama_ota");
listView = findViewById(R.id.lv_detpro);
layout_kupon = findViewById(R.id.layout_kupon);
header_promo = layout_kupon.findViewById(R.id.header_promo_tv);
kupon_promo = layout_kupon.findViewById(R.id.kode_promo_tv);
notif_promo = layout_kupon.findViewById(R.id.notif_promo_tv);
requestQueue = Volley.newRequestQueue(this);
nama_detail_promo_tv = findViewById(R.id.nama_detail_promo);
nama_detail_promo_tv.setText(nama_detail_promo);
setDetailPromotoClass(id_link_promo);
adapter = new DetailPromoAdapter(detailPromos,this);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Promo "+nama_ota);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
//Set kupon
System.out.println("Size detpro "+counter_header+" "+counter_promo);
if(counter_header == 0 && counter_promo == 0){
notif_promo.setVisibility(View.VISIBLE);
header_promo.setVisibility(View.GONE);
kupon_promo.setVisibility(View.GONE);
System.out.println("Masuk sini");
}
else if(counter_header == 0){
header_promo.setText("PROMO PESAWAT");
}
else{
kupon_promo.setText("Tidak perlu");
}
}
class DetailPromoAdapter extends BaseAdapter {
private List<DetailPromo> detailPromo;
private Context context;
public DetailPromoAdapter(List<DetailPromo> detailPromo, Context context) {
this.detailPromo = detailPromo;
this.context = context;
}
#Override
public int getCount() {
System.out.println("Detail promo size"+detailPromo.size());
return detailPromo.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = getLayoutInflater().inflate(R.layout.detail_promo_adapter, parent, false);
TextView nama_detail_promo = convertView.findViewById(R.id.isi_detail_promo);
if(detailPromo.get(position).getDetpro_role().equals("detail_promo")){
nama_detail_promo.setText(detailPromo.get(position).getDetpro_list());
}
return convertView;
}
}
public void setDetailPromotoClass(int id_linkpro){
detailPromos = new ArrayList<DetailPromo>();
String url_promo = "http://"+url+"/detail_promo/"+id_linkpro;
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url_promo, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("data");
for(int i=0; i<jsonArray.length(); i++){
JSONObject data_promo = jsonArray.getJSONObject(i);
int id_detpro = data_promo.getInt("id");
int id_promo = data_promo.getInt("promo_id");
int id_linkpro = data_promo.getInt("linkpro_id");
String detpro_list = data_promo.getString("detpro_list");
String detpro_role = data_promo.getString("detpro_role");
detailPromos.add(new DetailPromo(id_detpro,id_promo,id_linkpro,detpro_list,detpro_role));
System.out.println("Data promo yang diklik "+id_promo+" "+id_linkpro+" "+detpro_list+" "+detpro_role);
adapter.notifyDataSetChanged();
if(detpro_role.equals("header_promo")){
header_promo.setText(detailPromos.get(i).detpro_list);
System.out.println("Ada header");
counter_header++;
}
if(detpro_role.equals("kode_promo")){
System.out.println("Ada kupon");
kupon_promo.setText(detailPromos.get(i).detpro_list);
counter_promo++;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
requestQueue.add(request);
}
}

com.google.firebase.database.databaseexception:firebase database error: Permission denied

im retrieving data in my database from firebase. and shoscription herew up this error can anyone help me? this is my mainactivity.java:
package com.example.infamouslegend.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
FirebaseDatabase database;
DatabaseReference myRef ;
List<FireModel> list;
RecyclerView recycle;
Button view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = (Button) findViewById(R.id.view);
recycle = (RecyclerView) findViewById(R.id.recycle);
database = FirebaseDatabase.getInstance();
myRef = database.getReference("Complaints");
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
list = new ArrayList<FireModel>();
for(DataSnapshot dataSnapshot1 :dataSnapshot.getChildren()){
FireModel value = dataSnapshot.getValue(FireModel.class);
FireModel fire = new FireModel();
String Description = value.getDescription();
String Date = value.getDate();
String MediaURL = value.getMediaURL();
fire.setDescription(Description);
fire.setDate(Date);
fire.setMediaURL(MediaURL);
list.add(fire);
}
}
#Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("Hello", "Failed to read value.", error.toException());
Toast.makeText(MainActivity.this, "Failed to read value !" + error.toException(), Toast.LENGTH_SHORT).show();
}
});
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RecyclerAdapter recyclerAdapter = new RecyclerAdapter(list,MainActivity.this);
RecyclerView.LayoutManager recyce = new GridLayoutManager(MainActivity.this,2);
/// RecyclerView.LayoutManager recyce = new LinearLayoutManager(MainActivity.this);
// recycle.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true));
recycle.setLayoutManager(recyce);
recycle.setItemAnimator( new DefaultItemAnimator());
recycle.setAdapter(recyclerAdapter);
}
});
}
}
and this is my firemodel.java:
package com.example.infamouslegend.myapplication;
/**
* Created by Infamous Legend on 10/15/2017.
*/
public class FireModel {
public String Description;
public String Date;
public String MediaURL;
public String getDescription() {
return Description;
}
public void setDescription(String description) {
this.Description = description;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
this.Date = date;
}
public String getMediaURL() {
return MediaURL;
}
public void setMediaURL(String MediaURL) {
this.MediaURL = MediaURL;
}
}
and my recycleradapter.java:
package com.example.infamouslegend.myapplication;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
/**
* Created by Infamous Legend on 10/15/2017.
*/
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyHoder>{
List<FireModel> list;
Context context;
public RecyclerAdapter(List<FireModel> list, Context context) {
this.list = list;
this.context = context;
}
#Override
public MyHoder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.card,parent,false);
MyHoder myHoder = new MyHoder(view);
return myHoder;
}
#Override
public void onBindViewHolder(MyHoder holder, int position) {
FireModel mylist = list.get(position);
holder.Description.setText(mylist.getDescription());
holder.Date.setText(mylist.getDate());
//holder.MediaURL.setText(mylist.getMediaURL());
//Picasso.with(context).load(MediaURL.get(position).getMediaURL()).resize(120, 60).into(MyHoder.MediaURL);
}
#Override
public int getItemCount() {
int arr = 0;
try{
if(list.size()==0){
arr = 0;
}
else{
arr=list.size();
}
}catch (Exception e){
}
return arr;
}
class MyHoder extends RecyclerView.ViewHolder{
TextView Description,Date;
//ImageView MediaURL;
public MyHoder(View itemView) {
super(itemView);
Description = (TextView) itemView.findViewById(R.id.vname);
Date= (TextView) itemView.findViewById(R.id.vemail);
//MediaURL= (ImageView) itemView.findViewById(R.id.thumbnail);
}
}
}
Can anyone help me this? Im trying to retrieve data from firebase database to recyclerview with cardview. Thanks in advance
this is my firebase realtime database rule:
{
"rules": {
".read": true,
".write":true
}
}
If you have configured the app to connect with firebase correctly i would redownload the google-service.json and replace with an existing one.
check this solution

Retrieve value of CheckBox from ListView and assign to Object in array list

I have an app that currently displays a list of names in a ListView. Each item in the ListView consists of a CheckBox and an EditText.
The list of names is provided by an ArrayList of 'Prospects' objects
When the user selects the CheckBox I want to return the state of this check box and assign it the Propsects object at the relevant position in the ArrayList so it can be saved for use the next time the app is opened (this will be done using CSV).
I'm struggling with the correct listener to use to do this as this is my first attempt at Android programming. I've been unable to find any examples that match what i'm trying to achieve or if I have i've not understood them!.
Any help would be appreciated!
My code is as follows:
package com.veetox.networkmarketingmanager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.veetox.networkmarketingmanager.data.Prospects;
import com.veetox.networkmarketingmanager.helper.FileHelper;
import com.veetox.networkmarketingmanager.helper.ProspectListAdapter;
import com.veetox.networkmarketingmanager.helper.ProspectViewHolder;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity
{
public static ArrayList<Prospects> prospectList = new ArrayList<>();
Resources res;
FileHelper fileHelper = new FileHelper(this);
ListView prospectsListEntry;
CheckBox prospectsCheckBox;
EditText prospectsEditText;
ProspectListAdapter pla;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prospectsCheckBox = (CheckBox) findViewById(R.id.pr_checkBox);
prospectsEditText = (EditText) findViewById(R.id.pr_name);
res = getResources();
createProspectList();
prospectsListEntry.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View item, int position, long id)
{
//Create new Prospect cloning Prospect at row in ItemList that was clicked
Prospects prospect = pla.getItem(position);
//Change the state of contacted from true to false or vice versa
prospect.toggleContacted();
//Create a ProspectViewHolder to hold the view for the row clicked
ProspectViewHolder viewHolder = (ProspectViewHolder) item.getTag();
viewHolder.getCheckBox().setChecked(prospect.isChecked());
prospectList.get(position) ;
pla.notifyDataSetChanged();
}
});
}
public void testProspects(View view)
{
prospectList = fileHelper.testProspects();
pla.notifyDataSetChanged();
}
public void createProspectList()
{
fileHelper = new FileHelper(this);
//Comment before testing
//prospectList = fileHelper.loadProspects();
//Uncomment for testing
prospectList = fileHelper.testProspects();
//Create the list
pla = new ProspectListAdapter(this, R.layout.prospects_list_layout, prospectList);
prospectsListEntry = (ListView) findViewById(R.id.prospects_list);
prospectsListEntry.setAdapter(pla);
}
}
package com.veetox.networkmarketingmanager.helper;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import com.veetox.networkmarketingmanager.MainActivity;
import com.veetox.networkmarketingmanager.R;
import com.veetox.networkmarketingmanager.data.Prospects;
import java.util.ArrayList;
/**
* Created by Matt on 29/09/2016.
*/
public class ProspectListAdapter extends ArrayAdapter<Prospects>
{
private Context context;
private int layoutResourceId;
private ArrayList<Prospects> prospect;
public ProspectListAdapter(Context context, int layoutResourceId, ArrayList<Prospects> prospect)
{
super(context, layoutResourceId, prospect);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.prospect = prospect;
}
public int getCount()
{
return prospect.size();
}
public Prospects getItem(int position)
{
return prospect.get(position);
}
public long getItemId(int position)
{
return position;
}
#Override
#NonNull
public View getView(int position, View convertView, #NonNull ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi;
vi = LayoutInflater.from(context);
v = vi.inflate(layoutResourceId, parent, false);
}
Prospects prospects = prospect.get(position);
if (prospects != null)
{
TextView prname = (TextView) v.findViewById(R.id.pr_name);
CheckBox complete = (CheckBox) v.findViewById(R.id.pr_checkBox);
if (prname != null)
{
prname.setText(prospects.getName());
}
if (complete != null)
{
complete.setChecked(prospects.isChecked());
}
}
return v;
}
}
package com.veetox.networkmarketingmanager.data;
/**
* A Prospective customer
*/
public class Prospects
{
private String prospectname;
private boolean contacted;
private String stringContacted;
public Prospects(String aName, boolean contacted)
{
prospectname = aName;
this.contacted = contacted;
}
public Prospects(String aName, String contacted)
{
prospectname = aName;
this.stringContacted = contacted;
}
public Prospects(String aName)
{
prospectname = aName;
}
public String getName()
{
return prospectname;
}
public boolean isChecked()
{
return contacted;
}
public void setName (String aName)
{
prospectname = aName;
}
public void setContacted(boolean contacted)
{
this.contacted = contacted;
}
public void toggleContacted()
{
if (contacted)
{
contacted = false;
}
else
{
contacted = true;
}
}
}
package com.veetox.networkmarketingmanager.helper;
import android.content.Context;
import android.widget.Toast;
import com.veetox.networkmarketingmanager.data.Prospects;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
/**
* Created by Matt on 28/09/2016.
*/
public final class FileHelper
{
Context context;
public FileHelper(Context aContext)
{
context = aContext;
}
public void saveProspects(ArrayList<Prospects> prospects)
{
ArrayList<Prospects> p = prospects;
BufferedWriter bufferedFileWriter = null;
try
{
File aFile = new File(context.getFilesDir(), "prospects.csv");
aFile.createNewFile();
bufferedFileWriter = new BufferedWriter(new FileWriter(aFile));
for (Prospects eachProspect : p)
{
bufferedFileWriter.write(eachProspect.getName());
bufferedFileWriter.write(",");
bufferedFileWriter.write(String.valueOf(eachProspect.isChecked()));
bufferedFileWriter.newLine();
}
}
catch (Exception e)
{
e.printStackTrace();
// Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
}
finally
{
try
{
bufferedFileWriter.close();
}
catch (Exception e)
{
e.printStackTrace();
//Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
public ArrayList<Prospects> loadProspects()
{
ArrayList<Prospects> prospectsList = new ArrayList<>();
Scanner bufferedScanner = null;
Scanner lineScanner = null;
try
{
File aFile = new File(context.getFilesDir(), "prospects.csv");
bufferedScanner = new Scanner(new BufferedReader(new FileReader(aFile)));
while (bufferedScanner.hasNextLine())
{
lineScanner = new Scanner(bufferedScanner.nextLine());
lineScanner.useDelimiter(",");
String prospect = lineScanner.next();
String contacted = lineScanner.next();
Prospects aProspect = new Prospects(prospect, contacted);
prospectsList.add(aProspect);
}
}
catch (Exception e)
{
e.printStackTrace();
//Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
}
finally
{
try
{
bufferedScanner.close();
}
catch (Exception e)
{
e.printStackTrace();
//Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
}
}
return prospectsList;
}
public ArrayList<Prospects> testProspects()
{
ArrayList<Prospects> p = new ArrayList<>();
Prospects q = new Prospects("Matt Lee", true);
Prospects r = new Prospects("Rosemary Watson", false);
Prospects s = new Prospects("Joe Bloggs", false);
Prospects t = new Prospects("Ronny Corbit", false);
Prospects u = new Prospects("Mr Man", false);
Prospects v = new Prospects("Mr Bond", true);
Prospects w = new Prospects("Mr Blobby", true);
Prospects x = new Prospects("Mary Rose", false);
Prospects y = new Prospects("Jane Doe", false);
Prospects z = new Prospects("Lucy Sanders", false);
p.add(q);
p.add(r);
p.add(s);
p.add(t);
p.add(u);
p.add(v);
p.add(w);
p.add(x);
p.add(y);
p.add(z);
return p;
}
}
You need to move your checkbox check(checked/notChecked) in adapter. you'll need ItemId to access and retrive the clicked item in ListView.

Recycler view not showing after parsing json data using Volley

Inside my tab bar i want to show my data in Recycler view by using json parsing using volley library. I parsed the data and it showing in toast perfectly.But in Recycler view its not showing Here is my codes.
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
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.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.xml.transform.ErrorListener;
import info.tatwa.adupter.AdupterBoxOffice;
import info.tatwa.extras.Keys;
import info.tatwa.extras.UrlEndPoint;
import info.tatwa.login.L;
import info.tatwa.model.Movies;
import info.tatwa.network.MyApplication;
import info.tatwa.network.VolleySingleton;
import info.tatwa.newnav.R;
import info.tatwa.extras.UrlEndPoint.*;
import info.tatwa.extras.Keys.EndpointBoxOffice.*;
public class FragmentBoxOffice extends Fragment {
private VolleySingleton volleySingleton;
private RequestQueue requestQueue;
private AdupterBoxOffice adupterBoxOffice;
private ArrayList<Movies>listMovie = new ArrayList<>();
private ImageLoader imageLoader;
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
public static final String ROTET_TOMATO_URL_BOX_OFFICE="My url is here"
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private RecyclerView listMovieHits;
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* #param param1 Parameter 1.
* #param param2 Parameter 2.
* #return A new instance of fragment FragmentBoxOffice.
*/
public static FragmentBoxOffice newInstance(String param1, String param2) {
FragmentBoxOffice fragment = new FragmentBoxOffice();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
public static String getRequestUrl(int limit){
//ROTET_TOMATO_URL_BOX_OFFICE+"?apikey="+ MyApplication.ROTET_TOMATO_API_KEY+"&limit="+limit;
return UrlEndPoint.URL_BOX_OFFICE +
UrlEndPoint.URL_CHAR_QUASTIAN+
UrlEndPoint.URL_CHAR_PAREM_APIKEY +
MyApplication.ROTET_TOMATO_API_KEY +
UrlEndPoint.URL_CHAR_APPEND+
UrlEndPoint.URL_CHAR_PAREM_LIMIT + limit;
}
public FragmentBoxOffice() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
volleySingleton = VolleySingleton.getsInstance();
requestQueue = volleySingleton.getmRequestQueue();
senJsonRequest();
}
public void senJsonRequest(){
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, getRequestUrl(10), (String)null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
paresJSONResponse(response);
listMovie =paresJSONResponse(response);
adupterBoxOffice.setMovieList(listMovie);
L.t(getActivity(), response.toString());
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(),"Error"+error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(request);
}
public ArrayList<Movies> paresJSONResponse(JSONObject response){
ArrayList<Movies> listMovie = new ArrayList<>();
if(response ==null|| response.length()==0 ){
return null;
}
try {
StringBuilder data = new StringBuilder();
JSONArray arrayMovie = response.getJSONArray(Keys.EndpointBoxOffice.KEY_MOVIES);
Log.v("BIKASH", "JSON Object id" + arrayMovie);
for(int i = 0; i<arrayMovie.length();i++){
JSONObject currentMovies= arrayMovie.getJSONObject(i);
Long id =currentMovies.getLong(Keys.EndpointBoxOffice.KEY_ID);
String title=currentMovies.getString(Keys.EndpointBoxOffice.KEY_TITLE);
JSONObject objectReleaseDates=currentMovies.getJSONObject(Keys.EndpointBoxOffice.KEY_RELEASE_DATES);
String releaseDate=null;
if(objectReleaseDates.has(Keys.EndpointBoxOffice.KEY_THEATER)){
releaseDate = objectReleaseDates.getString(Keys.EndpointBoxOffice.KEY_THEATER);
}
else {
releaseDate="NA";
}
int audianceRatting=-1;
JSONObject objectRatting = currentMovies.getJSONObject(Keys.EndpointBoxOffice.KEY_RATINGS);
{
if(objectRatting.has(Keys.EndpointBoxOffice.KEY_AUDIENCE_SCORE)){
audianceRatting=objectRatting.getInt(Keys.EndpointBoxOffice.KEY_AUDIENCE_SCORE);
}
}
String synuypsis = currentMovies.getString(Keys.EndpointBoxOffice.KEY_SYNOPSIS);
String urlThumbnel = null;
JSONObject objPoster = currentMovies.getJSONObject(Keys.EndpointBoxOffice.KEY_THUMBNAIL);
if(objPoster.has(Keys.EndpointBoxOffice.KEY_THUMBNAIL)){
urlThumbnel = objPoster.getString(Keys.EndpointBoxOffice.KEY_THUMBNAIL);
}
Movies movie =new Movies();
movie.setId(id);
movie.setTitle(title);
Date date = dateFormat.parse(releaseDate);
movie.setReleaseDateTheater(date);
movie.setAudienceScore(audianceRatting);
movie.setSynopsis(synuypsis);
movie.setUrlThumbnail(urlThumbnel);
listMovie.add(movie);
// data.append(id + "\n");
}
L.t(getActivity(),listMovie.toString());
} catch (JSONException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return listMovie;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view =inflater.inflate(R.layout.fragment_fragment_box_office, container, false);
listMovieHits =(RecyclerView)view.findViewById(R.id.listMovieHits);
listMovieHits.setLayoutManager(new LinearLayoutManager(getActivity()));
adupterBoxOffice = new AdupterBoxOffice(getActivity());
listMovieHits.setAdapter(adupterBoxOffice);
senJsonRequest();
return view;
}
}
My Adupter
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import java.util.ArrayList;
import info.tatwa.model.Movies;
import info.tatwa.myfragment.FragmentBoxOffice;
import info.tatwa.network.VolleySingleton;
import info.tatwa.newnav.R;
public class AdupterBoxOffice extends RecyclerView.Adapter<AdupterBoxOffice.ViewHolderBoxOffice> {
private LayoutInflater layoutInflater;
FragmentBoxOffice activity;
private ArrayList<Movies> listMovie = new ArrayList<>();
private VolleySingleton volleySingleton;
private ImageLoader imageLoader;
public AdupterBoxOffice(Context context){
layoutInflater=LayoutInflater.from(context);
volleySingleton=VolleySingleton.getsInstance();
imageLoader = volleySingleton.getImageLoader();
}
public void setMovieList(ArrayList<Movies>listMovie){
this.listMovie = listMovie;
notifyItemRangeChanged(0,listMovie.size());
}
#Override
public ViewHolderBoxOffice onCreateViewHolder(ViewGroup parent, int viewType) {
layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.movie_list_itom,parent,false);
ViewHolderBoxOffice viewHolder =new ViewHolderBoxOffice(view);
return viewHolder;
}
#Override
public void onBindViewHolder(final ViewHolderBoxOffice holder, int position) {
Movies currentMovie =listMovie.get(position);
holder.movieTitle.setText(currentMovie.getTitle());
holder.movieReleaseDate.setText(currentMovie.getReleaseDateTheater().toString());
holder.movieRatting.setRating(currentMovie.getAudienceScore()/20.0f);
String urlThumbnel = currentMovie.getUrlThumbnail();
if(urlThumbnel!=null){
imageLoader.get(urlThumbnel, new ImageLoader.ImageListener() {
#Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
holder.imagePoster.setImageBitmap(response.getBitmap());
}
#Override
public void onErrorResponse(VolleyError error) {
}
});
}
}
#Override
public int getItemCount() {
return listMovie.size();
}
static class ViewHolderBoxOffice extends RecyclerView.ViewHolder {
private ImageView imagePoster;
private TextView movieTitle;
private TextView movieReleaseDate;
private RatingBar movieRatting;
public ViewHolderBoxOffice(View itemView) {
super(itemView);
imagePoster=(ImageView)itemView.findViewById(R.id.movieThumbnail);
movieTitle =(TextView)itemView.findViewById(R.id.movieTitle);
movieReleaseDate=(TextView)itemView.findViewById(R.id.movieReleaseDate);
movieRatting=(RatingBar)itemView.findViewById(R.id.movieAudienceScore);
}
}
}
And My Model class
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Date;
public class Movies{
private long id;
private String title;
private Date releaseDateTheater;
private int audienceScore;
private String synopsis;
private String urlThumbnail;
private String urlSelf;
private String urlCast;
private String urlReviews;
private String urlSimilar;
public Movies() {
}
public Movies(long id,
String title,
Date releaseDateTheater,
int audienceScore,
String synopsis,
String urlThumbnail,
String urlSelf,
String urlCast,
String urlReviews,
String urlSimilar) {
this.id = id;
this.title = title;
this.releaseDateTheater = releaseDateTheater;
this.audienceScore = audienceScore;
this.synopsis = synopsis;
this.urlThumbnail = urlThumbnail;
this.urlSelf = urlSelf;
this.urlCast = urlCast;
this.urlReviews = urlReviews;
this.urlSimilar = urlSimilar;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getReleaseDateTheater() {
return releaseDateTheater;
}
public void setReleaseDateTheater(Date releaseDateTheater) {
this.releaseDateTheater = releaseDateTheater;
}
public int getAudienceScore() {
return audienceScore;
}
public void setAudienceScore(int audienceScore) {
this.audienceScore = audienceScore;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public String getUrlThumbnail() {
return urlThumbnail;
}
public void setUrlThumbnail(String urlThumbnail) {
this.urlThumbnail = urlThumbnail;
}
public String getUrlSelf() {
return urlSelf;
}
public void setUrlSelf(String urlSelf) {
this.urlSelf = urlSelf;
}
public String getUrlCast() {
return urlCast;
}
public void setUrlCast(String urlCast) {
this.urlCast = urlCast;
}
public String getUrlReviews() {
return urlReviews;
}
public void setUrlReviews(String urlReviews) {
this.urlReviews = urlReviews;
}
public String getUrlSimilar() {
return urlSimilar;
}
public void setUrlSimilar(String urlSimilar) {
this.urlSimilar = urlSimilar;
}
#Override
public String toString() {
return "\nID: " + id +
"\nTitle " + title +
"\nDate " + releaseDateTheater +
"\nSynopsis " + synopsis +
"\nScore " + audienceScore +
"\nurlThumbnail " + urlThumbnail +
"\nurlSelf " + urlSelf +
"\nurlCast " + urlCast +
"\nurlReviews " + urlReviews +
"\nurlSimilar " + urlSimilar +
"\n";
}
}
Please help me out .. Thanks in advance ..
After adupterBoxOffice.setMovieList(listMovie);
try add adupterBoxOffice.notifyDataSetChanged();
I found my solution.I put some wrong key during pars the Json. That's why my ArrayList returning zero.
Many many thanks to all for helping me out.

Categories

Resources