2017-01-24 73 views
0

我有一個模型類「JobPostBean」,我在另一個模型類中啓動並使用第二個模型類添加數據。我想清除所有保存在「JobPostBean」類中的數據。有沒有什麼方法可以在「JobPostBean」類中或者在初始化的第二個模型類中清除它?我寧願使用單一方法清除它,而不是將「JobPostBean」類中的每個項目設置爲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; 
 
    } 
 
}

+0

你是什麼意思在另一個班級保存?將其插入另一個項目後,您可以從列表中刪除任何項目。 –

+0

如果您只是再次實例化模型類,它將獲得新的引用,並且對象所保存的以前的數據將會消失。 – fluffyBatman

回答

0
public ArrayList<JobPostBean > al_JobPostBean = new ArrayList<JobPostBean >(); // Declare as global 

在ArrayList中。如果第一次保存數據,你想刪除所有數據,則可以清除ArrayList

al_JobPostBean.clear(); 

的clear()方法刪除ArrayList的所有元素。

+0

所以,我不能清除pojo類而不聲明ArrayList? 另外,如果我清除Arraylist,Pojo類會被清除嗎? –

+1

嗯,我不認爲我會要求這個,因爲我試過fluffyBatman的解決方案,它的工作。我重新啓動了課程並清除了數據。謝謝@fluffyBatman –

+0

@SomnathPal繼續前進。 –