I actually want cardView in my RecyclerView to retrieve data from firebase but it returns error. Please do help me to attach my RecyclerView to firebase and retrieve data from it.
Thanking you in advance.
Here is the mainActivity.java
mbloglist = findViewById(R.id.rv1);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
productAdapter adapter = new productAdapter(this);
mbloglist.setLayoutManager(layoutManager);
mbloglist.setAdapter(adapter);
Toast.makeText(getApplicationContext(),"Layout starting",Toast.LENGTH_SHORT).show();
database1 = FirebaseDatabase.getInstance();
myRef = database1.getReference("Users");
Toast.makeText(getApplicationContext(),"Database Done",Toast.LENGTH_SHORT).show();
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.e("pppp","onDataChange"+dataSnapshot.toString());
Toast.makeText(getApplicationContext(),"Done",Toast.LENGTH_SHORT).show();
for(DataSnapshot child : dataSnapshot.getChildren()){
ModelClass modelClass = child.getValue(ModelClass.class);
modelClassList.add(modelClass);
}
Toast.makeText(getApplicationContext(),"Done Done",Toast.LENGTH_SHORT).show();
adapter.addItems(modelClassList);
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.e("pppp","onCancelled");
}
});
}
Here is the Adapter which named ProductAdapter.java
public productAdapter(Context context) {
this.context = context;
this.productList = new ArrayList<>();
}
public void addItems(List<ModelClass> productList){
this.productList = productList;
this.notifyDataSetChanged();
}
#NonNull
#Override
public productViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return new productViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view,parent,false));
}
#Override
public void onBindViewHolder(#NonNull productViewHolder holder, int position) {
ModelClass modelClass = productList.get(position);
holder.shop_name.setText(modelClass.getStore_name());
holder.phone_number.setText(modelClass.getphone_number());
holder.v7b.setText(modelClass.getV7b());
holder.v7g.setText(modelClass.getV7g());
holder.y53b.setText(modelClass.getY53b());
holder.y53g.setText(modelClass.getY53g());
holder.v7pb.setText(modelClass.getV7pb());
holder.v7pg.setText(modelClass.getV7pg());
holder.y55sb.setText(modelClass.getY55sb());
holder.y55sg.setText(modelClass.getY55sb());
holder.i3b.setText(modelClass.getI3b());
holder.i3go.setText(modelClass.getI3go());
holder.i3gr.setText(modelClass.getI3gr());
holder.i3prob.setText(modelClass.getI3prob());
holder.i3progo.setText(modelClass.getI3progo());
holder.i3progr.setText(modelClass.getI3progr());
holder.i5b.setText(modelClass.getI5b());
holder.i5go.setText(modelClass.getI5go());
holder.i5gr.setText(modelClass.getI5gr());
holder.i5prob.setText(modelClass.getI5prob());
holder.i5progo.setText(modelClass.getI5progo());
holder.i5progr.setText(modelClass.getI5progr());
holder.i7b.setText(modelClass.getI7b());
holder.i7go.setText(modelClass.getI7go());
holder.i7gr.setText(modelClass.getI7gr());
holder.camonb.setText(modelClass.getCamonb());
holder.camongo.setText(modelClass.getCamongo());
holder.camonbl.setText(modelClass.getCamonbl());
}
#Override
public int getItemCount() {
return 0;
}
class productViewHolder extends RecyclerView.ViewHolder{
private TextView shop_name,phone_number,v7b,v7g,y53b,y53g,v7pb,v7pg,y55sb,y55sg,y69b,y69g,i3b,i3go,i3gr,i3prob,i3progo,i3progr,i5b,i5go,i5gr,i5prob,i5progo,i5progr,i7b,i7go,i7gr,camonb,camongo,camonbl;
public productViewHolder(View itemView){
super(itemView);
shop_name = itemView.findViewById(R.id.EditText2000);
phone_number=itemView.findViewById(R.id.EditText2001);
v7b=itemView.findViewById(R.id.EditText101);
v7g=itemView.findViewById(R.id.EditText102);
y53b=itemView.findViewById(R.id.EditText103);
y53g=itemView.findViewById(R.id.EditText104);
v7pb=itemView.findViewById(R.id.EditText105);
v7pg=itemView.findViewById(R.id.EditText106);
y55sb=itemView.findViewById(R.id.EditText107);
y55sg=itemView.findViewById(R.id.EditText108);
y69b=itemView.findViewById(R.id.EditText109);
y69g=itemView.findViewById(R.id.EditText110);
i3b=itemView.findViewById(R.id.EditText111);
i3go=itemView.findViewById(R.id.EditText112);
i3gr=itemView.findViewById(R.id.EditText113);
i3prob=itemView.findViewById(R.id.EditText114);
i3progo=itemView.findViewById(R.id.EditText115);
i3progr=itemView.findViewById(R.id.EditText116);
i5b=itemView.findViewById(R.id.EditText117);
i5go=itemView.findViewById(R.id.EditText118);
i5gr=itemView.findViewById(R.id.EditText119);
i5prob=itemView.findViewById(R.id.EditText120);
i5progo=itemView.findViewById(R.id.EditText121);
i5progr=itemView.findViewById(R.id.EditText122);
i7b=itemView.findViewById(R.id.EditText123);
i7go=itemView.findViewById(R.id.EditText124);
i7gr=itemView.findViewById(R.id.EditText125);
camonb=itemView.findViewById(R.id.EditText126);
camongo=itemView.findViewById(R.id.EditText127);
camonbl=itemView.findViewById(R.id.EditText128);
Here is the modelclass.java which attached to firebase
public class ModelClass {
String v7b;
String v7g;
String y53b;
String y53g;
String v7pb;
String v7pg;
String y55sb;
String y55sg;
String y69b;
String y69g;
String i3b;
String i3go;
String i3gr;
String i3prob;
String i3progo;
String i3progr;
String i5b;
String i5go;
String i5gr;
String i5prob;
String i5progo;
String i5progr;
String i7b;
String i7go;
String i7gr;
String camonb;
String camongo;
String camonbl;
String email;
String store_name;
String phone_number;
public ModelClass() {
}
public ModelClass(String v7b, String v7g, String y53b, String y53g, String v7pb, String v7pg, String y55sb, String y55sg, String y69b, String y69g, String i3b, String i3go, String i3gr, String i3prob, String i3progo, String i3progr, String i5b, String i5go, String i5gr, String i5prob, String i5progo, String i5progr, String i7b, String i7go, String i7gr, String camonb, String camongo, String camongr) {
this.v7b = v7b;
this.v7g = v7g;
this.y53b = y53b;
this.y53g = y53g;
this.v7pb = v7pb;
this.v7pg = v7pg;
this.y55sb = y55sb;
this.y55sg = y55sg;
this.y69b = y69b;
this.y69g = y69g;
this.i3b = i3b;
this.i3go = i3go;
this.i3gr = i3gr;
this.i3prob = i3prob;
this.i3progo = i3progo;
this.i3progr = i3progr;
this.i5b = i5b;
this.i5go = i5go;
this.i5gr = i5gr;
this.i5prob = i5prob;
this.i5progo = i5progo;
this.i5progr = i5progr;
this.i7b = i7b;
this.i7go = i7go;
this.i7gr = i7gr;
this.camonb = camonb;
this.camongo = camongo;
this.camonbl = camongr;
}
public ModelClass(String email, String store_name, String phone_number) {
this.email = email;
this.store_name = store_name;
this.phone_number = phone_number;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPhone() {
return phone;
}
String phone;
public String getV7b() {
return v7b;
}
public void setV7b(String v7b) {
this.v7b = v7b;
}
public String getV7g() {
return v7g;
}
public void setV7g(String v7g) {
this.v7g = v7g;
}
public String getY53b() {
return y53b;
}
public void setY53b(String y53b) {this.y53b = y53b;}
public String getY53g() {
return y53g;
}
public void setY53g(String y53g) {
this.y53g = y53g;
}
public String getV7pb() {
return v7pb;
}
public void setV7pb(String v7pb) {
this.v7pb = v7pb;
}
public String getV7pg() {
return v7pg;
}
public void setV7pg(String v7pg) {
this.v7pg = v7pg;
}
public String getY55sb() {
return y55sb;
}
public void setY55sb(String y55sb) {
this.y55sb = y55sb;
}
public String getY55sg() {
return y55sg;
}
public void setY55sg(String y55sg) {
this.y55sg = y55sg;
}
public String getY69b() {
return y69b;
}
public void setY69b(String y69b) {
this.y69b = y69b;
}
public String getY69g() {
return y69g;
}
public void setY69g(String y69g) {
this.y69g = y69g;
}
public String getI3b() {
return i3b;
}
public void setI3b(String i3b) {
this.i3b = i3b;
}
public String getI3go() {
return i3go;
}
public void setI3go(String i3go) {
this.i3go = i3go;
}
public String getI3gr() {
return i3gr;
}
public void setI3gr(String i3gr) {
this.i3gr = i3gr;
}
public String getI3prob() {
return i3prob;
}
public void setI3prob(String i3prob) {
this.i3prob = i3prob;
}
public String getI3progo() {
return i3progo;
}
public void setI3progo(String i3progo) {
this.i3progo = i3progo;
}
public String getI3progr() {
return i3progr;
}
public void setI3progr(String i3progr) {
this.i3progr = i3progr;
}
public String getI5b() {
return i5b;
}
public void setI5b(String i5b) {
this.i5b = i5b;
}
public String getI5go() {
return i5go;
}
public void setI5go(String i5go) {
this.i5go = i5go;
}
public String getI5gr() {
return i5gr;
}
public void setI5gr(String i5gr) {
this.i5gr = i5gr;
}
public String getI5prob() {
return i5prob;
}
public void setI5prob(String i5prob) {
this.i5prob = i5prob;
}
public String getI5progo() {
return i5progo;
}
public void setI5progo(String i5progo) {
this.i5progo = i5progo;
}
public String getI5progr() {
return i5progr;
}
public void setI5progr(String i5progr) {
this.i5progr = i5progr;
}
public String getI7b() {
return i7b;
}
public void setI7b(String i7b) {
this.i7b = i7b;
}
public String getI7go() {
return i7go;
}
public void setI7go(String i7go) {
this.i7go = i7go;
}
public String getI7gr() {
return i7gr;
}
public void setI7gr(String i7gr) {
this.i7gr = i7gr;
}
public String getCamonb() {
return camonb;
}
public void setCamonb(String camonb) {
this.camonb = camonb;
}
public String getCamongo() {
return camongo;
}
public void setCamongo(String camongo) {
this.camongo = camongo;
}
public String getCamonbl() {
return camonbl;
}
public void setCamongr(String camongr) {
this.camonbl = camongr;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getStore_name() {
return store_name;
}
public void setStorename(String storename) {this.store_name = storename;}
public String getphone_number() {
return phone_number;
}
public void setphone_number(String phone_number) {
this.phone_number = phone_number;
}
}
Here is the Firebase Realtime Database Image
ModelClass class and your database doesn't have the same structure, because in your database you have a new node called "phone" inside each userID node.
You can try 3 approaches to solve this issue:
a.) Write data in your database just like ModelClass is, without "phone" node.
b.) Create a new class called "Phone" with same attributes you have inside "phone" node in the database, and make this new class part of ModelClass class.
c.) On myRef onDataChange method, inside for statement, check for each child key and fill ModelClass atributes one by one. When the child key is equal to "phone", start a new loop statement in "phone" children to fill these attributes.
Add the following code:
#Override
public int getItemCount() {
return productList.size();
}
Related
I am trying to communicate with an API using Retrofit in Android Studios but do not know how to get the JSON array within a JSON object.
JSON:
{
"result":{
"status":{
"msg":"success",
"code":200,
"action":2,
"execution_time":"0.505"
},
"page":"1",
"page_size":"40",
"q":"iphone",
"sort":"default",
"tmall":false,
"free_shiping":false,
"total_results":1924963,
"ip":"13.228.169.5",
"item":[
{
"num_iid":619354061232,
"pic":"https://img.alicdn.com/bao/uploaded/i4/2150908574/O1CN01O3Akm82DCwTChbTXg_!!2150908574.jpg",
"title":"Apple/苹果 iPhone XR iphone xs max手机双卡国行原装4G xr苹果x",
"price":"6000",
"promotion_price":"2009",
"sales":1973,
"loc":"广东 深圳",
"seller_id":2150908574,
"seller_nick":"实惠馆超市",
"shop_title":"新魔方数码",
"user_type":0,
"detail_url":"https://item.taobao.com/item.htm?id=619354061232",
"delivery_fee":"0.00"
}
"item":[...]
Method:
private void taobaoSearch(){
TaobaoInterface retrofitInterface = RetrofitInstance.getRetrofitInstanceTaobao().create(TaobaoInterface.class);
Call<TaobaoModel> listCall = retrofitInterface.getTaobao("item_search", "40","default", "iphone","taobao-api.p.rapidapi.com", "//apikey hidden");
listCall.enqueue(new Callback<TaobaoModel>() {
#Override
public void onResponse(Call<TaobaoModel> call, Response<TaobaoModel> response) {
//not sure what to do here
}
#Override
public void onFailure(Call<TaobaoModel> call, Throwable t) {
System.out.println("FAILED");
System.out.println(call);
t.printStackTrace();
}
});
}
TaobaoModel:
public class TaobaoModel {
#SerializedName("result")
private Result result;
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
}
Result:
public class Result {
#SerializedName("status")
private Status status;
#SerializedName("q")
private String q;
#SerializedName("page")
private String page;
#SerializedName("page_size")
private String page_size;
#SerializedName("total_results")
private int total_results;
#SerializedName("tmall")
private String tmall;
#SerializedName("sort")
private String sort;
#SerializedName("free_shiping")
private String free_shiping;
#SerializedName("ip")
private String ip;
#SerializedName("item")
private ArrayList<TaobaoItems> item;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getQ() {
return q;
}
public void setQ(String q) {
this.q = q;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getPage_size() {
return page_size;
}
public void setPage_size(String page_size) {
this.page_size = page_size;
}
public int getTotal_results() {
return total_results;
}
public void setTotal_results(int total_results) {
this.total_results = total_results;
}
public String getTmall() {
return tmall;
}
public void setTmall(String tmall) {
this.tmall = tmall;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getFree_shiping() {
return free_shiping;
}
public void setFree_shiping(String free_shiping) {
this.free_shiping = free_shiping;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public ArrayList<TaobaoItems> getItem() {
return item;
}
public void setItem(ArrayList<TaobaoItems> item) {
this.item = item;
}
}
TaobaoItems
public class TaobaoItems {
#SerializedName("num_iid")
private long num_iid;
#SerializedName("pic")
private String pic;
#SerializedName("title")
private String title;
#SerializedName("price")
private String price;
#SerializedName("promotion_price")
private String promotion_price;
#SerializedName("sales")
private int sales;
#SerializedName("loc")
private String loc;
#SerializedName("seller_id")
private long seller_id;
#SerializedName("seller_nick")
private String seller_nick;
#SerializedName("shop_title")
private String shop_title;
#SerializedName("user_type")
private int user_type;
#SerializedName("detail_url")
private String detail_url;
#SerializedName("delivery_fee")
private String delivery_fee;
public TaobaoItems(String title, String price, String pic, String detail_url) {
this.pic = pic;
this.title = title;
this.price = price;
this.detail_url = detail_url;
}
public long getNum_iid() {
return num_iid;
}
public void setNum_iid(long num_iid) {
this.num_iid = num_iid;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getPromotion_price() {
return promotion_price;
}
public void setPromotion_price(String promotion_price) {
this.promotion_price = promotion_price;
}
public int getSales() {
return sales;
}
public void setSales(int sales) {
this.sales = sales;
}
public String getLoc() {
return loc;
}
public void setLoc(String loc) {
this.loc = loc;
}
public long getSeller_id() {
return seller_id;
}
public void setSeller_id(long seller_id) {
this.seller_id = seller_id;
}
public String getSeller_nick() {
return seller_nick;
}
public void setSeller_nick(String seller_nick) {
this.seller_nick = seller_nick;
}
public String getShop_title() {
return shop_title;
}
public void setShop_title(String shop_title) {
this.shop_title = shop_title;
}
public int getUser_type() {
return user_type;
}
public void setUser_type(int user_type) {
this.user_type = user_type;
}
public String getDetail_url() {
return detail_url;
}
public void setDetail_url(String detail_url) {
this.detail_url = detail_url;
}
public String getDelivery_fee() {
return delivery_fee;
}
public void setDelivery_fee(String delivery_fee) {
this.delivery_fee = delivery_fee;
}
}
Status:
public class Status {
#SerializedName("msg")
private String msg;
#SerializedName("code")
private int code;
#SerializedName("action")
private int action;
#SerializedName("execution_time")
private String execution_time;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public int getAction() {
return action;
}
public void setAction(int action) {
this.action = action;
}
public String getExecution_time() {
return execution_time;
}
public void setExecution_time(String execution_time) {
this.execution_time = execution_time;
}
}
My intention is to get the JSON Array item and display title,price,pic,detail_url from it. I found out how to display it one at a time so far, but couldn't find how to iterate the JSON object so that I can display the data in a listview. Please help, I am new to this and I've been stuck for quite awhile now. If you want to see my interface, retrofit instance etc just let me know.
private void taobaoSearch(){
TaobaoInterface retrofitInterface = RetrofitInstance.getRetrofitInstanceTaobao().create(TaobaoInterface.class);
Call<TaobaoModel> listCall = retrofitInterface.getTaobao("item_search", "40","default", "iphone","taobao-api.p.rapidapi.com", "//apikey hidden");
listCall.enqueue(new Callback<TaobaoModel>() {
#Override
public void onResponse(Call<TaobaoModel> call, Response<TaobaoModel> response) {
List<Result> retro=response.body().getitems();
generateDataList(retro);
}
#Override
public void onFailure(Call<TaobaoModel> call, Throwable t) {
System.out.println("FAILED");
System.out.println(call);
t.printStackTrace();
}
});
}
/*Method to generate List of data using RecyclerView with custom adapter*/
private void generateDataList(List<Result> dataList) {
recyclerView = findViewById(R.id.customRecycler);
adapter = new CustomAdapter(this,dataList);
recyclerView.setAdapter(adapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
}
I am trying to insert realm lists to my realmdb in my first insert there is no problem but when I insert another realmList with a different class, my old values are deleted. So how can I insert a realmlist to DB? inserts are done separately.
RealmList<Product> insertedProduct = new RealmList<Product>();
RealmList<ProductSubCategory> insertedSubCategory = new RealmList<ProductSubCategory>();
RealmList<ProductMainCategory> insertedMainCategory = new RealmList<ProductMainCategory>();
... inserting to realm list firt time ...
insertRealmList(insertedProduct); //inserting to realmDB first time
insertRealmList(insertedSubCategory); //inserting to realmDB first time
insertRealmList(insertedMainCategory); //inserting to realmDB first time
first insert to realmDB
RealmList insert function
private void insertRealmList(final RealmList realmObject) {
mRealm = Realm.getDefaultInstance();
realmTask = mRealm.executeTransactionAsync(
new Realm.Transaction() {
#Override
public void execute(Realm realm) {
realm.copyToRealmOrUpdate(realmObject);
}
},
new Realm.Transaction.OnSuccess() {
#Override
public void onSuccess() {
Log.i(TAG, "onSuccess: successfully inserted data");
}
},
new Realm.Transaction.OnError() {
#Override
public void onError(Throwable error) {
Log.i(TAG, "onError: error while inserting " + "error: " + error);
}
}
);
}
... inserting to realm list second time...
insertRealmList(insertedLanguages); //insert realmDB second time
second insert to realmDB
PRODUCT MODEL
package Model;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.Index;
import io.realm.annotations.PrimaryKey;
public class Product extends RealmObject {
#PrimaryKey
#Index
private int ID;
#Index
private int PLU_NO;
private String PRODUCT_NAME;
private String MAIN_CATEGORY;
private String SUB_CATEGORY;
private String TYPE;
private String TUS;
private Double PRICE;
private String CALORIE;
private String COOKING_TIME;
private RealmList<String> PRODUCT_NAME_LANGUAGES;
private RealmList<String> PRODUCT_DESCRIPTION_LANGUAGES;
private String IMAGE_BASE_HORIZONTAL; //4/3
private String IMAGE_BASE_VERTICAL; //16/9
private String VIDEO_NAME; //video name
#Ignore
private int AMOUNT;
#Ignore
private int WINDOW_AMOUNT = 1;
public Product(int ID, int PLU_NO, String PRODUCT_NAME, String MAIN_CATEGORY, String SUB_CATEGORY, String TYPE, String TUS, Double PRICE, String CALORIE, String COOKING_TIME, RealmList<String> PRODUCT_NAME_LANGUAGES, RealmList<String> PRODUCT_DESCRIPTION_LANGUAGES, String IMAGE_BASE_HORIZONTAL, String IMAGE_BASE_VERTICAL, String VIDEO_NAME) {
this.ID = ID;
this.PLU_NO = PLU_NO;
this.PRODUCT_NAME = PRODUCT_NAME;
this.MAIN_CATEGORY = MAIN_CATEGORY;
this.SUB_CATEGORY = SUB_CATEGORY;
this.TYPE = TYPE;
this.TUS = TUS;
this.PRICE = PRICE;
this.CALORIE = CALORIE;
this.COOKING_TIME = COOKING_TIME;
this.PRODUCT_NAME_LANGUAGES = PRODUCT_NAME_LANGUAGES;
this.PRODUCT_DESCRIPTION_LANGUAGES = PRODUCT_DESCRIPTION_LANGUAGES;
this.IMAGE_BASE_HORIZONTAL = IMAGE_BASE_HORIZONTAL;
this.IMAGE_BASE_VERTICAL = IMAGE_BASE_VERTICAL;
this.VIDEO_NAME = VIDEO_NAME;
}
public Product() {
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public int getPLU_NO() {
return PLU_NO;
}
public void setPLU_NO(int PLU_NO) {
this.PLU_NO = PLU_NO;
}
public String getPRODUCT_NAME() {
return PRODUCT_NAME;
}
public void setPRODUCT_NAME(String PRODUCT_NAME) {
this.PRODUCT_NAME = PRODUCT_NAME;
}
public String getMAIN_CATEGORY() {
return MAIN_CATEGORY;
}
public void setMAIN_CATEGORY(String MAIN_CATEGORY) {
this.MAIN_CATEGORY = MAIN_CATEGORY;
}
public String getSUB_CATEGORY() {
return SUB_CATEGORY;
}
public void setSUB_CATEGORY(String SUB_CATEGORY) {
this.SUB_CATEGORY = SUB_CATEGORY;
}
public String getTYPE() {
return TYPE;
}
public void setTYPE(String TYPE) {
this.TYPE = TYPE;
}
public String getTUS() {
return TUS;
}
public void setTUS(String TUS) {
this.TUS = TUS;
}
public Double getPRICE() {
return PRICE;
}
public void setPRICE(Double PRICE) {
this.PRICE = PRICE;
}
public String getCALORIE() {
return CALORIE;
}
public void setCALORIE(String CALORIE) {
this.CALORIE = CALORIE;
}
public String getCOOKING_TIME() {
return COOKING_TIME;
}
public void setCOOKING_TIME(String COOKING_TIME) {
this.COOKING_TIME = COOKING_TIME;
}
public RealmList<String> getPRODUCT_NAME_LANGUAGES() {
return PRODUCT_NAME_LANGUAGES;
}
public void setPRODUCT_NAME_LANGUAGES(RealmList<String> PRODUCT_NAME_LANGUAGES) {
this.PRODUCT_NAME_LANGUAGES = PRODUCT_NAME_LANGUAGES;
}
public RealmList<String> getPRODUCT_DESCRIPTION_LANGUAGES() {
return PRODUCT_DESCRIPTION_LANGUAGES;
}
public void setPRODUCT_DESCRIPTION_LANGUAGES(RealmList<String> PRODUCT_DESCRIPTION_LANGUAGES) {
this.PRODUCT_DESCRIPTION_LANGUAGES = PRODUCT_DESCRIPTION_LANGUAGES;
}
public String getIMAGE_BASE_HORIZONTAL() {
return IMAGE_BASE_HORIZONTAL;
}
public void setIMAGE_BASE_HORIZONTAL(String IMAGE_BASE_HORIZONTAL) {
this.IMAGE_BASE_HORIZONTAL = IMAGE_BASE_HORIZONTAL;
}
public String getIMAGE_BASE_VERTICAL() {
return IMAGE_BASE_VERTICAL;
}
public void setIMAGE_BASE_VERTICAL(String IMAGE_BASE_VERTICAL) {
this.IMAGE_BASE_VERTICAL = IMAGE_BASE_VERTICAL;
}
public String getVIDEO_NAME() {
return VIDEO_NAME;
}
public void setVIDEO_NAME(String VIDEO_NAME) {
this.VIDEO_NAME = VIDEO_NAME;
}
public int getAMOUNT() {
return AMOUNT;
}
public void setAMOUNT(int AMOUNT) {
this.AMOUNT = AMOUNT;
}
public int getWINDOW_AMOUNT() {
return WINDOW_AMOUNT;
}
public void setWINDOW_AMOUNT(int WINDOW_AMOUNT) {
this.WINDOW_AMOUNT = WINDOW_AMOUNT;
}
public void setDEFAULT_WINDOW_AMOUNT() {
this.WINDOW_AMOUNT = 1;
}
}
LANGUAGE MODEL
package Model;
import io.realm.RealmObject;
public class Language extends RealmObject {
#PrimaryKey
#Index
private int ID;
private String ICON;
private String NAME;
public Language(){
}
public Language(int ID, String ICON, String NAME) {
this.ID = ID;
this.ICON = ICON;
this.NAME = NAME;
}
public int getId() {
return ID;
}
public void setId(int id) {
this.ID = id;
}
public String getICON() {
return ICON;
}
public void setICON(String ICON) {
this.ICON = ICON;
}
public String getName() {
return NAME;
}
public void setName(String name) {
this.NAME = name;
}
}
Other two models are similar with product.
Please try the following method:
private <T extends RealmModel> void insertRealmList(final List<T> objects) {
try (Realm realmInstance = Realm.getDefaultInstance()) {
realmInstance.executeTransaction(realm -> {
for (T object : objects) {
realmInstance.insertOrUpdate(object);
}
});
}
}
Hope this helps!
I have set switch box in adapter when switch box is enable then open custom check box list item. I have select check box item multiple. This switch box design when select spinner item and then open fragment page. When select multiple check box item and send JSON param like this:
"attendees": [
{
"id": "1",
"person": "xza"
},
{
"id": "2",
"person": "cfd"
}
]
And send button applying in activity. Spinner and save button design in activity and select item design in fragment.
I have make model class like:
public class MeetingModel {
public String date;
public String time;
public boolean reminder;
public boolean assignTOther;
public boolean contactTo;
public boolean attendeesTo;
public String remark;
private MeetingReminder meetingReminder;
private int assignid;
private int contactid;
private List<Assigne> attendees = null;
private int attendeesid;
private String location;
private String purpose;
private String clientType;
private String id;
private String logSubType;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public boolean isReminder() {
return reminder;
}
public void setReminder(boolean reminder) {
this.reminder = reminder;
}
public boolean isAssignTOther() {
return assignTOther;
}
public void setAssignTOther(boolean assignTOther) {
this.assignTOther = assignTOther;
}
public boolean isContactTo() {
return contactTo;
}
public void setContactTo(boolean contactTo) {
this.contactTo = contactTo;
}
public boolean isAttendeesTo() {
return attendeesTo;
}
public void setAttendeesTo(boolean attendeesTo) {
this.attendeesTo = attendeesTo;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public MeetingReminder getMeetingReminder() {
return meetingReminder;
}
public void setMeetingReminder(MeetingReminder meetingReminder) {
this.meetingReminder = meetingReminder;
}
public int getAssignid() {
return assignid;
}
public void setAssignid(int assignid) {
this.assignid = assignid;
}
public int getContactid() {
return contactid;
}
public void setContactid(int contactid) {
this.contactid = contactid;
}
public void setMeetingReminder(String date, String time) {
MeetingReminder meetingReminder = new MeetingReminder();
meetingReminder.setDate(date);
meetingReminder.setTime(time);
setMeetingReminder(meetingReminder);
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getPurpose() {
return purpose;
}
public void setPurpose(String purpose) {
this.purpose = purpose;
}
public String getClientType() {
return clientType;
}
public void setClientType(String clientType) {
this.clientType = clientType;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLogSubType() {
return logSubType;
}
public void setLogSubType(String logSubType) {
this.logSubType = logSubType;
}
public List<Assigne> getAttendees() {
return attendees;
}
public void setAttendees(List<Assigne> attendees) {
this.attendees = attendees;
}
public JsonArray getCheckedItems(){
List<Assigne> tmpList=new ArrayList<>();
List<Assigne> attendees = new ArrayList<>();
JsonArray jsonArray = new JsonArray();
for(Assigne attendee:attendees){
if(attendee.isHeaderSelected()){
tmpList.add(attendee);
attendee.setHeaderSelected(true);
JsonObject obj = new JsonObject();
obj.addProperty("id", attendee.getId());
obj.addProperty("name", attendee.getName());
jsonArray.add(obj);
}
}
return jsonArray;
}
}
I expect the output is:
"attendees":[{"id":"1","person":"fff"},{"id":"2","person":"dfdf"}]
But the actual output is:
"attendees": []
I am trying to access getter property of the pojo received in the response, but there is no such option.so is there any other way, I can do that?
The code for that call is as below:
results.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<GenericResponse<List<FoodTruck>>>() {
#Override
public void onCompleted() {
Toast.makeText(getActivity(), "completed", Toast.LENGTH_SHORT).show();
unsubscribe();
}
#Override
public void onError(Throwable e) {
Toast.makeText(getActivity(), "error", Toast.LENGTH_SHORT).show();
}
#Override
public void onNext(GenericResponse<List<FoodTruck>> response) {
Toast.makeText(getActivity(), response.toString(), Toast.LENGTH_SHORT).show();
}
});
GenericResponse.java
public class GenericResponse<T> {
#JsonProperty("status")
private String status;
#JsonProperty("message")
private String message;
#JsonProperty("data")
private T data;
}
FoodTruck.java
#JsonInclude(JsonInclude.Include.NON_NULL)
public class FoodTruck implements Parcelable {
#JsonProperty("_id")
private String foodTruckId;
#JsonProperty("foodtruck_name")
private String foodTruckName;
#JsonProperty("foodtruck_location")
private String foodTruckLocation;
#JsonProperty("foodtruck_tag")
private String foodTruckTag;
#JsonProperty("foodtruck_timing")
private String foodTruckTiming;
#JsonProperty("foodtruck_cusine")
private String foodTruckCusine;
#JsonProperty("foodtruck_img")
private String foodTruckImg;
#JsonProperty("foodtruck_logo")
private String foodTruckLogo;
#JsonProperty("foodtruck_total_votes")
private int foodTruckTotalVotes;
#JsonProperty("foodtruck_rating")
private double foodTruckRating;
#JsonProperty("item_list")
private List<FoodTruckItem> foodTruckItemList;
public String getFoodTruckId() {
return foodTruckId;
}
public String getFoodTruckName() {
return foodTruckName;
}
public String getFoodTruckLocation() {
return foodTruckLocation;
}
public String getFoodTruckTag() {
return foodTruckTag;
}
public String getFoodTruckTiming() {
return foodTruckTiming;
}
public String getFoodTruckCusine() {
return foodTruckCusine;
}
public String getFoodTruckImg() {
return foodTruckImg;
}
public String getFoodTruckLogo() {
return foodTruckLogo;
}
public int getFoodTruckTotalVotes() {
return foodTruckTotalVotes;
}
public double getFoodTruckRating() {
return foodTruckRating;
}
public List<FoodTruckItem> getFoodTruckItemList() {
return foodTruckItemList;
}
public void setFoodTruckId(String foodTruckId) {
this.foodTruckId = foodTruckId;
}
public void setFoodTruckName(String foodTruckName) {
this.foodTruckName = foodTruckName;
}
public void setFoodTruckLocation(String foodTruckLocation) {
this.foodTruckLocation = foodTruckLocation;
}
public void setFoodTruckTag(String foodTruckTag) {
this.foodTruckTag = foodTruckTag;
}
public void setFoodTruckTiming(String foodTruckTiming) {
this.foodTruckTiming = foodTruckTiming;
}
public void setFoodTruckCusine(String foodTruckCusine) {
this.foodTruckCusine = foodTruckCusine;
}
public void setFoodTruckImg(String foodTruckImg) {
this.foodTruckImg = foodTruckImg;
}
public void setFoodTruckLogo(String foodTruckLogo) {
this.foodTruckLogo = foodTruckLogo;
}
public void setFoodTruckTotalVotes(int foodTruckTotalVotes) {
this.foodTruckTotalVotes = foodTruckTotalVotes;
}
public void setFoodTruckRating(double foodTruckRating) {
this.foodTruckRating = foodTruckRating;
}
public void setFoodTruckItemList(List<FoodTruckItem> foodTruckItemList) {
this.foodTruckItemList = foodTruckItemList;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.foodTruckId);
dest.writeString(this.foodTruckName);
dest.writeString(this.foodTruckLocation);
dest.writeString(this.foodTruckTag);
dest.writeString(this.foodTruckTiming);
dest.writeString(this.foodTruckCusine);
dest.writeString(this.foodTruckImg);
dest.writeString(this.foodTruckLogo);
dest.writeInt(this.foodTruckTotalVotes);
dest.writeDouble(this.foodTruckRating);
dest.writeTypedList(this.foodTruckItemList);
}
public FoodTruck() {
}
protected FoodTruck(Parcel in) {
this.foodTruckId = in.readString();
this.foodTruckName = in.readString();
this.foodTruckLocation = in.readString();
this.foodTruckTag = in.readString();
this.foodTruckTiming = in.readString();
this.foodTruckCusine = in.readString();
this.foodTruckImg = in.readString();
this.foodTruckLogo = in.readString();
this.foodTruckTotalVotes = in.readInt();
this.foodTruckRating = in.readDouble();
this.foodTruckItemList = in.createTypedArrayList(FoodTruckItem.CREATOR);
}
public static final Parcelable.Creator<FoodTruck> CREATOR = new Parcelable.Creator<FoodTruck>() {
#Override
public FoodTruck createFromParcel(Parcel source) {
return new FoodTruck(source);
}
#Override
public FoodTruck[] newArray(int size) {
return new FoodTruck[size];
}
};
}
FoodTruckItem.java
#JsonInclude(JsonInclude.Include.NON_NULL)
public class FoodTruckItem implements Parcelable {
#JsonProperty("_id")
private String itemId;
#JsonProperty("no_of_times_ordered")
private int noOfTimesOrdered;
#JsonProperty("item_name")
private String itemName;
#JsonProperty("item_tag")
private String itemTag;
#JsonProperty("item_category")
private String itemCategory;
#JsonProperty("item_stock")
private int itemStock;
#JsonProperty("item_price")
private double itemPrice;
#JsonProperty("item_img")
private String itemImg;
#JsonProperty("no_of_likes")
private int noOfLikes;
#JsonProperty("item_quantity_ordered")
private int itemQuantityOrdered;
#JsonProperty("item_illustrations")
private List<String> itemIllustration;
public String getItemId() {
return itemId;
}
public int getNoOfTimesOrdered() {
return noOfTimesOrdered;
}
public String getItemName() {
return itemName;
}
public String getItemTag() {
return itemTag;
}
public String getItemCategory() {
return itemCategory;
}
public int getItemStock() {
return itemStock;
}
public double getItemPrice() {
return itemPrice;
}
public String getItemImg() {
return itemImg;
}
public int getNoOfLikes() {
return noOfLikes;
}
public int getItemQuantityOrdered() {
return itemQuantityOrdered;
}
public List<String> getItemIllustration() {
return itemIllustration;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public void setNoOfTimesOrdered(int noOfTimesOrdered) {
this.noOfTimesOrdered = noOfTimesOrdered;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public void setItemTag(String itemTag) {
this.itemTag = itemTag;
}
public void setItemCategory(String itemCategory) {
this.itemCategory = itemCategory;
}
public void setItemStock(int itemStock) {
this.itemStock = itemStock;
}
public void setItemPrice(double itemPrice) {
this.itemPrice = itemPrice;
}
public void setItemImg(String itemImg) {
this.itemImg = itemImg;
}
public void setNoOfLikes(int noOfLikes) {
this.noOfLikes = noOfLikes;
}
public void setItemQuantityOrdered(int itemQuantityOrdered) {
this.itemQuantityOrdered = itemQuantityOrdered;
}
public void setItemIllustration(List<String> itemIllustration) {
this.itemIllustration = itemIllustration;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.itemId);
dest.writeInt(this.noOfTimesOrdered);
dest.writeString(this.itemName);
dest.writeString(this.itemTag);
dest.writeString(this.itemCategory);
dest.writeInt(this.itemStock);
dest.writeDouble(this.itemPrice);
dest.writeString(this.itemImg);
dest.writeInt(this.noOfLikes);
dest.writeInt(this.itemQuantityOrdered);
dest.writeStringList(this.itemIllustration);
}
public FoodTruckItem() {
}
protected FoodTruckItem(Parcel in) {
this.itemId = in.readString();
this.noOfTimesOrdered = in.readInt();
this.itemName = in.readString();
this.itemTag = in.readString();
this.itemCategory = in.readString();
this.itemStock = in.readInt();
this.itemPrice = in.readDouble();
this.itemImg = in.readString();
this.noOfLikes = in.readInt();
this.itemQuantityOrdered = in.readInt();
this.itemIllustration = in.createStringArrayList();
}
public static final Parcelable.Creator<FoodTruckItem> CREATOR = new Parcelable.Creator<FoodTruckItem>() {
#Override
public FoodTruckItem createFromParcel(Parcel source) {
return new FoodTruckItem(source);
}
#Override
public FoodTruckItem[] newArray(int size) {
return new FoodTruckItem[size];
}
};
}
Now Basically I want to acess someting like response.getData().... But there is no such option.
Possibly data not accessible, because it is private. Try to crete getter method.
public class GenericResponse<T> {
#JsonProperty("status")
private String status;
#JsonProperty("message")
private String message;
#JsonProperty("data")
private T data;
public T getData() {
return data;
}
}
I am using tabs which consist of fragment that has an arraylist of objects. I want to store my arraylist
list<Model_BarcodeDetail>
onStop() ie., I want to store my list that is present in my current tab when I navigate to another tab. I did the following code but it is giving me exception when I'm trying to save my list.
#Override
public void onPause() {
// TODO Auto-generated method stub
super.onPause();
System.out.println("=====pause");
saveDatas();
}
public void saveDatas() {
Log.d("msg", "Save Instance");
SharedPreferences.Editor outState = getActivity().getSharedPreferences(
"order", Context.MODE_APPEND).edit();
text = editText_barcode.getText().toString();
itemQuantity = editText_quantity.getText().toString();
outState.putString("saved", "true");
outState.putString("text", text);
outState.putString("title", job_name);
outState.putString("area", selected_area);
outState.putString("location", selected_loc);
outState.putString("quantity", itemQuantity);
//String strObject = gson.toJson(list, Model_BarcodeDetail.class);
//outState.putString("MyList", strObject);
POJO mPojo = new POJO();
mPojo.setData(list);
String strObject = gson.toJson(mPojo, POJO.class);
outState.putString("MyList", strObject);
outState.commit();
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
Bundle extras = getArguments();
/***** PUT DATA IN EDITTEXT if ITS AVAILABLE IN BUNDLE *****/
System.out.println("===jobname:"+job_name);
SharedPreferences orderData = getActivity().getSharedPreferences(
"order", Context.MODE_APPEND);
if (orderData != null) {
String a = orderData.getString("saved", "");
if (a != null && a.equalsIgnoreCase("true")) {
text = orderData.getString("text", "");
System.out.println("====tetx:" + text);
String title = orderData.getString("title", "");
System.out.println("===title: "+title+"===jobname: "+job_name);
if (title.equalsIgnoreCase(job_name)) {
editText_barcode.setText(text);
selected_area = orderData.getString("area", "");
selected_loc = orderData.getString("location", "");
itemQuantity = orderData.getString("quantity", "");
editText_quantity.setText(itemQuantity);
String json = orderData.getString("MyList", "");
List<Model_BarcodeDetail> list = gson.fromJson(json,
listOfObjects);
}
}
}
}
I'm getting the following exception when I add another tab:
12-09 12:08:28.072: E/AndroidRuntime(28616): FATAL EXCEPTION: main
12-09 12:08:28.072: E/AndroidRuntime(28616): Process: com.example.pdt, PID:
28616
12-09 12:08:28.072: E/AndroidRuntime(28616): java.lang.NullPointerException
12-09 12:08:28.072: E/AndroidRuntime(28616): at
com.example.pdt.Fragment_Main.saveDatas(Fragment_Main.java:446)
12-09 12:08:28.072: E/AndroidRuntime(28616): at
com.example.pdt.Fragment_Main.onPause(Fragment_Main.java:426)
12-09 12:08:28.072: E/AndroidRuntime(28616): at
android.support.v4.app.Fragment.performPause(Fragment.java:1950)
12-09 12:08:28.072: E/AndroidRuntime(28616): at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1005)
12-09 12:08:28.072: E/AndroidRuntime(28616): at
android.support.v4.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1235)
EDIT:
Model_BarcodeDetail class:
package com.example.model;
public class Model_BarcodeDetail {
public String datetime, success, name, reference, description, price,
color, size, stock, branch, supplier, location, basesell, vat,
avg_cost, last_cost, next_cost, group_code, type, remarks1,
remarks2, listed_days, title, meta_keywords, meta_description,
job_id, total, fixedTotal, fixedPrice, aliascode, draftName,
itemBarcode, totalDiscount;
boolean priceEdited;
public boolean isPriceEdited() {
return priceEdited;
}
public void setPriceEdited(boolean priceEdited) {
this.priceEdited = priceEdited;
}
private String string_sale_return;
public String barcode, quantity = "0", area, batch;
private boolean scanned, isEdited;
public String getTotalDiscount() {
return totalDiscount;
}
public void setTotalDiscount(String totalDiscount) {
this.totalDiscount = totalDiscount;
}
public String getItemBarcode() {
return itemBarcode;
}
public void setItemBarcode(String itemBarcode) {
this.itemBarcode = itemBarcode;
}
public String getDraftName() {
return draftName;
}
public void setDraftName(String draftName) {
this.draftName = draftName;
}
public String getAliascode() {
return aliascode;
}
public void setAliascode(String aliascode) {
this.aliascode = aliascode;
}
public String getString_sale_return() {
return string_sale_return;
}
public void setString_sale_return(String string_sale_return) {
this.string_sale_return = string_sale_return;
}
public boolean isScanned() {
return scanned;
}
public void setScanned(boolean scanned) {
this.scanned = scanned;
}
public String getJob_id() {
return job_id;
}
public void setJob_id(String job_id) {
this.job_id = job_id;
}
public String getBatch() {
return batch;
}
public void setBatch(String batch) {
this.batch = batch;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getDatetime() {
return datetime;
}
public void setDatetime(String datetime) {
this.datetime = datetime;
}
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getStock() {
return stock;
}
public void setStock(String stock) {
this.stock = stock;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
public String getSupplier() {
return supplier;
}
public void setSupplier(String supplier) {
this.supplier = supplier;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getBasesell() {
return basesell;
}
public void setBasesell(String basesell) {
this.basesell = basesell;
}
public String getVat() {
return vat;
}
public void setVat(String vat) {
this.vat = vat;
}
public String getAvg_cost() {
return avg_cost;
}
public void setAvg_cost(String avg_cost) {
this.avg_cost = avg_cost;
}
public String getLast_cost() {
return last_cost;
}
public void setLast_cost(String last_cost) {
this.last_cost = last_cost;
}
public String getNext_cost() {
return next_cost;
}
public void setNext_cost(String next_cost) {
this.next_cost = next_cost;
}
public String getGroup_code() {
return group_code;
}
public void setGroup_code(String group_code) {
this.group_code = group_code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getRemarks1() {
return remarks1;
}
public void setRemarks1(String remarks1) {
this.remarks1 = remarks1;
}
public String getRemarks2() {
return remarks2;
}
public void setRemarks2(String remarks2) {
this.remarks2 = remarks2;
}
public String getListed_days() {
return listed_days;
}
public void setListed_days(String listed_days) {
this.listed_days = listed_days;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getMeta_keywords() {
return meta_keywords;
}
public void setMeta_keywords(String meta_keywords) {
this.meta_keywords = meta_keywords;
}
public String getMeta_description() {
return meta_description;
}
public void setMeta_description(String meta_description) {
this.meta_description = meta_description;
}
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public boolean isEdited() {
return isEdited;
}
public void setEdited(boolean isEdited) {
this.isEdited = isEdited;
}
public String getFixedTotal() {
return fixedTotal;
}
public void setFixedTotal(String fixedTotal) {
this.fixedTotal = fixedTotal;
}
public String getFixedPrice() {
return fixedPrice;
}
public void setFixedPrice(String fixedPrice) {
this.fixedPrice = fixedPrice;
}
}
POJO class:
package com.example.model;
import java.util.List;
public class Pojo {
List<Model_BarcodeDetail> data;
public List<Model_BarcodeDetail> getData() {
return data;
}
public void setData(List<Model_BarcodeDetail> data) {
this.data = data;
}
}
You need to store your list in the model class like this
public class POJO {
List<Model_BarcodeDetail> data;
public List<Model_BarcodeDetail> getData() {
return data;
}
public void setData(List<Model_BarcodeDetail> data) {
this.data = data;
}
}
now when you have data in your POJO class
Convert it to json string and store to prefrence like this
String strObject = gson.toJson(list, POJO.class);
outState.putString("MyList", strObject);
Now when you want to get back those data just do like this
String json = orderData.getString("MyList", "");
POJO mPojo = gson.fromJson(json,POJO.class);
now access you List using this object like this
mPojo.getModel_BarcodeList();
Let me know if you still have an issue
You can use TinyDB -- Android-Shared-Preferences-Turbo