Adding items to Realm database changes some variables - android

This is the code I have:
for (SearchData searchData1 : searchDataTemp){
Log.i("", "test is favourite searchdata:" + searchData1.getIs_favorite() + "..name: " + searchData1.getTitle());
}
Realm realm = Realm.getInstance(getActivity());
realm.beginTransaction();
List<SearchData> managedSeachData = realm.copyToRealmOrUpdate(searchDataTemp);
realm.commitTransaction();
for (SearchData searchData1 : managedSeachData) {
Log.i("", "test is favourite searchdata:" + searchData1.getIs_favorite() + "..name: " + searchData1.getTitle());
user.getRecents().add(searchData1);
}
This is what I get for the normal list in my logs:
test is favourite searchdata:true..name: Vondelpark
This is what I get for the managed Realmlist in my logs:
test is favourite searchdata:false..name: Vondelpark
Any ideea how this can be fixed?
PS: This is my SearchData model:
public class SearchData extends RealmObject{
#PrimaryKey
private String id;
private String title;
private String subtitle;
private String reference;
private String place_id;
private boolean is_favorite;
private int timestamp;
private String last_travel_mode;
private Geometry geometry;
private double distance;
private boolean close;
private int visited_count;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getPlace_id() {
return place_id;
}
public void setPlace_id(String place_id) {
this.place_id = place_id;
}
public boolean getIs_favorite() {
return is_favorite;
}
public void setIs_favorite(boolean is_favorite) {
this.is_favorite = is_favorite;
}
public int getTimestamp() {
return timestamp;
}
public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}
public String getLast_travel_mode() {
return last_travel_mode;
}
public void setLast_travel_mode(String last_travel_mode) {
this.last_travel_mode = last_travel_mode;
}
public Geometry getGeometry() {
return geometry;
}
public void setGeometry(Geometry geometry) {
this.geometry = geometry;
}
public double getDistance() {
return distance;
}
public void setDistance(double distance) {
this.distance = distance;
}
public boolean isClose() {
return close;
}
public void setClose(boolean close) {
this.close = close;
}
public boolean is_favorite() {
return is_favorite;
}
public int getVisited_count() {
return visited_count;
}
public void setVisited_count(int visited_count) {
this.visited_count = visited_count;
}
public SearchData() {
}
public SearchData(String id, String title, String subtitle, String reference, String place_id, boolean is_favorite, int timestamp, String last_travel_mode , int visited_count){
this.id = id;
this.title = title;
this.subtitle = subtitle;
this.reference = reference;
this.place_id = place_id;
this.is_favorite = is_favorite;
this.timestamp = timestamp;
this.last_travel_mode = last_travel_mode;
this.visited_count = visited_count;
}
public SearchData(String id, String title, String subtitle, String reference, String place_id, boolean is_favorite, int timestamp, String last_travel_mode, Geometry geometry , int visited_count){
this.id = id;
this.title = title;
this.subtitle = subtitle;
this.reference = reference;
this.place_id = place_id;
this.is_favorite = is_favorite;
this.timestamp = timestamp;
this.last_travel_mode = last_travel_mode;
this.geometry = geometry;
this.visited_count = visited_count;
}
}

SearchData class has both getIs_favorite() and is_favorite().
In that case, Realm annotation processor overrides only is_favorite().
That's why getIs_favorite() returns always false.

Related

Firebase test lab result : No properties to serialize found on class com.example.poultryscope.ItemModel

My application works well in debug mode, I Generated a signed Android app bundle and tested it by firebase test lab but app crashed during testing.
the test shows Fatal exception :
java.lang.RuntimeException: No properties to serialize found on class com.example.poultryscope.ItemModel
here is the error
and this is the ItemModel class :
public class ItemModel implements Serializable {
//recyclerview
private int id;
private String name;
private String nickname;
private int image;
//firestore
private String title;
private List<String> introduction;
private List<String> signs;
private List<String> postmortem;
private String img1;
private String img2;
private String img3;
private String img4;
private String img5;
private String img6;
private String img7;
private String img8;
private String collapsingPhoto;
private List<String> prevention;
private List<String> treatment;
public ItemModel() {
}
public ItemModel(String title, List<String> introduction, List<String> signs, List<String> postmortem, String img1, String img2, String img3, String img4, String img5, String img6, String img7, String img8,String collapsingPhoto, List<String> prevention, List<String> treatment) {
this.title = title;
this.introduction = introduction;
this.signs = signs;
this.postmortem = postmortem;
this.img1 = img1;
this.img2 = img2;
this.img3 = img3;
this.img4 = img4;
this.img5 = img5;
this.img6 = img6;
this.img7 = img7;
this.img8 = img8;
this.collapsingPhoto = collapsingPhoto;
this.prevention = prevention;
this.treatment = treatment;
}
public ItemModel(String name, String nickname, int image) {
this.name = name;
this.nickname = nickname;
this.image = image;
}
public ItemModel(int id, String name) {
this.id = id;
this.name = name;
}
public ItemModel(String name, String nickname) {
this.name = name;
this.nickname = nickname;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getIntroduction() {
return introduction;
}
public void setIntroduction(List<String> introduction) {
this.introduction = introduction;
}
public List<String> getSigns() {
return signs;
}
public void setSigns(List<String> signs) {
this.signs = signs;
}
public List<String> getPostmortem() {
return postmortem;
}
public void setPostmortem(List<String> postmortem) {
this.postmortem = postmortem;
}
public String getImg1() {
return img1;
}
public void setImg1(String img1) {
this.img1 = img1;
}
public String getImg2() {
return img2;
}
public void setImg2(String img2) {
this.img2 = img2;
}
public String getImg3() {
return img3;
}
public void setImg3(String img3) {
this.img3 = img3;
}
public String getImg4() {
return img4;
}
public void setImg4(String img4) {
this.img4 = img4;
}
public String getImg5() {
return img5;
}
public void setImg5(String img5) {
this.img5 = img5;
}
public String getImg6() {
return img6;
}
public void setImg6(String img6) {
this.img6 = img6;
}
public String getImg7() {
return img7;
}
public void setImg7(String img7) {
this.img7 = img7;
}
public String getImg8() {
return img8;
}
public void setImg8(String img8) {
this.img8 = img8;
}
public String getCollapsingPhoto() {
return collapsingPhoto;
}
public void setCollapsingPhoto(String collapsingPhoto) {
this.collapsingPhoto = collapsingPhoto;
}
public List<String> getPrevention() {
return prevention;
}
public void setPrevention(List<String> prevention) {
this.prevention = prevention;
}
public List<String> getTreatment() {
return treatment;
}
public void setTreatment(List<String> treatment) {
this.treatment = treatment;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public void setImage(int image) {
this.image = image;
}
public int getImage() {
return image;
}
}
this is the proguard-rules.pro file :
The error was resolved after Adding #Keep in the ItemModel class beginning instead of writing it in the proguard-rules.pro file.

How to insert RealmList to RealmDB

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!

Android Nested Objects and Retrofit2

I am reading a JSON like this:
{
"matches": [{
"id": 246119,
"utcDate": "2018-08-17T18:15:00Z",
"status": "FINISHED",
"homeTeam": {
"id": 298,
"name": "Girona FC"
},
"awayTeam": {
"id": 250,
"name": "Real Valladolid CF"
},
"score": {
"winner": "DRAW",
"duration": "REGULAR"
}
}]
}
I must say that the JSON is valid. I am consuming this JSON through an API. I can correctly read the properties "id", "utc" and "status", but I could not with "score", "awayTeam" and "homeTeam". I don't really know how to work those properties. I'd like to handle each propertie of score, awayTeam, and homeTeam individually, for example, I want to get just the name of awayTeam and homeTeam and the 2 properties of score.
This, is my code:
MainActivity
public class MainActivity extends AppCompatActivity {
private Retrofit retrofit;
private static final String TAG = "Football";
private RecyclerView recyclerView;
private ListaPartidosAdapter listaPartidosAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
listaPartidosAdapter = new ListaPartidosAdapter(this);
recyclerView.setAdapter(listaPartidosAdapter);
recyclerView.setHasFixedSize(true);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this, VERTICAL, true);
recyclerView.setLayoutManager(layoutManager);
retrofit = new Retrofit.Builder()
.baseUrl("http://api.football-data.org/v2/")
.addConverterFactory(GsonConverterFactory.create())
.build();
obtenerDatos();
}
private void obtenerDatos() {
footballdataService service = retrofit.create(footballdataService.class);
Call<PartidosRespuesta> partidosRespuestaCall = service.obtenerlistaPartidos();
partidosRespuestaCall.enqueue(new Callback<PartidosRespuesta>() {
#Override
public void onResponse(Call<PartidosRespuesta> call, Response<PartidosRespuesta> response) {
if(response.isSuccessful()) {
PartidosRespuesta partidosRespuesta = response.body();
ArrayList<Partido> listaPartidos = partidosRespuesta.getMatches();
listaPartidosAdapter.adicionarListaPartidos(listaPartidos);
}
else {
Log.e(TAG, "onResponse: " + response.errorBody());
}
}
#Override
public void onFailure(Call<PartidosRespuesta> call, Throwable t) {
Log.e(TAG, "onFailure: " + t.getMessage());
}
});
}
}
Now this is my interface. footballdataService
public interface footballdataService {
#GET("competitions/2014/matches")
Call<PartidosRespuesta> obtenerlistaPartidos();
}
This is PartidosRespuestas class
public class PartidosRespuesta {
private ArrayList<Partido> matches;
public ArrayList<Partido> getMatches() {
return matches;
}
public void setMatches(ArrayList<Partido> matches) {
this.matches = matches;
}
}
This, is the adapter.
public class ListaPartidosAdapter extends RecyclerView.Adapter<ListaPartidosAdapter.ViewHolder> {
private static final String TAG = "Football_Adapter";
private ArrayList<Partido> dataset;
private Context context;
public ListaPartidosAdapter(Context context) {
this.context = context;
dataset = new ArrayList<Partido>();
}
#Override
public ListaPartidosAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_partidos, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(ListaPartidosAdapter.ViewHolder holder, int position) {
Partido p = dataset.get(position);
holder.status.setText(p.getId());
}
#Override
public int getItemCount() {
return dataset.size();
}
public void adicionarListaPartidos(ArrayList<Partido> listaPartidos){
dataset.addAll(listaPartidos);
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView status;
public ViewHolder(View itemView) {
super(itemView);
status = (TextView) itemView.findViewById(R.id.status);
}
}
}
And this.., is Partido class
public class Partido {
private String id;
private String utcDate;
private String status;
private EquipoCasa homeTeam;
private EquipoVisita AwayTeam;
private Puntaje score;
public String getId() {
return id;
}
public String getUtcDate() {
return utcDate;
}
public String getStatus() {
return status;
}
public EquipoCasa getHomeTeam() {
return homeTeam;
}
public EquipoVisita getAwayTeam() {
return AwayTeam;
}
public Puntaje getScore() {
return score;
}
public void setId(String id) {
this.id = id;
}
public void setUtcDate(String utcDate) {
this.utcDate = utcDate;
}
public void setStatus(String status) {
this.status = status;
}
public void setHomeTeam(EquipoCasa homeTeam) {
this.homeTeam = homeTeam;
}
public void setAwayTeam(EquipoVisita awayTeam) {
AwayTeam = awayTeam;
}
public void setScore(Puntaje score) {
this.score = score;
}
public class EquipoCasa {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class EquipoVisita {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Puntaje {
private String winner;
private String duration;
public String getWinner() {
return winner;
}
public void setWinner(String winner) {
this.winner = winner;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
}
}
POJO classes of your code should this:
AwayTeam.java
//AwayTeam
public class AwayTeam {
#SerializedName("id")
#Expose
private Integer id;
#SerializedName("name")
#Expose
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
PartidosRespuesta.java
//Object response
public class PartidosRespuesta {
#SerializedName("matches")
#Expose
private List<Match> matches = null;
public List<Match> getMatches() {
return matches;
}
public void setMatches(List<Match> matches) {
this.matches = matches;
}
}
HomeTeam.java
//HomeTeam
public class HomeTeam {
#SerializedName("id")
#Expose
private Integer id;
#SerializedName("name")
#Expose
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Score.java
//Score
public class Score {
#SerializedName("winner")
#Expose
private String winner;
#SerializedName("duration")
#Expose
private String duration;
public String getWinner() {
return winner;
}
public void setWinner(String winner) {
this.winner = winner;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
}
Edit:
#Override
public void onBindViewHolder(ListaPartidosAdapter.ViewHolder holder, int position) {
Partido p = dataset.get(position);
HomeTeam homeTeam = p.getHomeTeam();
String nameHomeTeam = homeTeam.getName();
}
And tool convert json to java code: http://www.jsonschema2pojo.org/
try
public class Puntaje {
public String winner;
public String duration;
}
It's seems like you've problems with your models. Use this link to convert your json to java object.

DBFlow make simple OneToMany relation ship

I'm trying to make simple relationShiop between two table as Sahmiyeand FoodData with OneToMany, in first time i get this error:
Error:(69, 42) error: cannot find symbol variable queenForeignKeyContainer_id
My Sahmiye class:
#Table(database = AppDatabase.class)
public class Sahmiye {
#PrimaryKey(autoincrement = true)
private int id;
#Column
private String title;
#Column
private String parentId;
public List<FoodData> foodData;
public Sahmiye() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public List<FoodData> getFoodData() {
return foodData;
}
public void setFoodData(List<FoodData> foodData) {
this.foodData = foodData;
}
#OneToMany(methods = {OneToMany.Method.ALL}, variableName = "foodData")
public List<FoodData> getMyFoodDatas() {
if (foodData == null || foodData.isEmpty()) {
foodData = SQLite.select()
.from(FoodData.class)
.where(FoodData_Table.queenForeignKeyContainer_id.eq(id))
.queryList();
}
return foodData;
}
}
and my FoodData Table:
#Table(database = AppDatabase.class)
public class FoodData {
#PrimaryKey(autoincrement = true)
private int id;
#Column
private String title;
#Column
private boolean rice;
#Column
private int foodId;
#Column
private int parentId;
public FoodData() {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean isRice() {
return rice;
}
public void setRice(boolean rice) {
this.rice = rice;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getFoodId() {
return foodId;
}
public void setFoodId(int foodId) {
this.foodId = foodId;
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
}
could you fix my relation ship? thanks in advance

Clear a Model class

I have a model class "JobPostBean" which I'm initiating in another model class and adding data using the second model class. I would like to clear any data which gets saved in the "JobPostBean" class. Is there any way to clear it either in "JobPostBean" class or in the second model class where its initialised? I would prefer to clear it using a single method rather than setting every item in the "JobPostBean" class to null.
public class BidNextJobDataModel {
private static BidNextJobDataModel ourInstance = new BidNextJobDataModel();
public static BidNextJobDataModel getInstance() {
return ourInstance;
}
private BidNextJobDataModel() {
}
public UserBean userBean;
// Here I initialised the class
public JobPostBean jobPostBean = new JobPostBean();
public ArrayList<FilterModel> filterModelArrayList = new ArrayList<FilterModel>();
public ArrayList<FilterModel> notificationModelArrayList = new ArrayList<FilterModel>();
public ArrayList<FilterModel> chooseCategoryArrayList = new ArrayList<FilterModel>();
public ArrayList<JobsBean> jobsBeanArrayList = new ArrayList<JobsBean>();
}
public class JobPostBean {
private String jobtype="";
private String days="";
private String hour="";
private String title="";
private String category="";
private String categorytxt="";
private String description="";
private String price="";
private String duration="";
private String is_certified="";
private String is_insure="";
private String is_experience="";
private String address="";
private String name="";
private String image="";
private String date="";
private String pricetype="";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getJobtype() {
return jobtype;
}
public void setJobtype(String jobtype) {
this.jobtype = jobtype;
}
public String getDays() {
return days;
}
public void setDays(String days) {
this.days = days;
}
public String getHour() {
return hour;
}
public void setHour(String hour) {
this.hour = hour;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getCategorytxt() {
return categorytxt;
}
public void setCategorytxt(String categorytxt) {
this.categorytxt = categorytxt;
}
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 getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getIs_certified() {
return is_certified;
}
public void setIs_certified(String is_certified) {
this.is_certified = is_certified;
}
public String getIs_insure() {
return is_insure;
}
public void setIs_insure(String is_insure) {
this.is_insure = is_insure;
}
public String getIs_experience() {
return is_experience;
}
public void setIs_experience(String is_experience) {
this.is_experience = is_experience;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPricetype() {
return pricetype;
}
public void setPricetype(String pricetype) {
this.pricetype = pricetype;
}
}
public ArrayList<JobPostBean > al_JobPostBean = new ArrayList<JobPostBean >(); // Declare as global
At first Hold Data in ArrayList .If you want delete all data then You can Clear ArrayList
al_JobPostBean.clear();
The clear() method removes all the elements of ArrayList .

Categories

Resources