我正在寻找一个简单的PC商店票系统。我有一个新的故障单活动,一个列表故障单活动和一个编辑故障单活动。该应用程序首先启动新的票证活动,如下所示
要在新故障单活动和列表故障单活动之间传递数据,我有一个实现parcelable的简单故障单对象,如下所示:
import android.icu.text.SimpleDateFormat;
import android.os.Parcel;
import android.os.Parcelable;
import java.text.ParseException;
import java.util.Date;
public class Ticket implements Parcelable {
private int ticket_id;
private String name, creation_date, problem, status, fix_date;
public Ticket(){}
public Ticket(int ticket_id, String name, String creation_date, String problem, String status, String fix_date){
this.ticket_id = ticket_id;
this.name = name;
this.creation_date = creation_date;
this.problem = problem;
this.status = status;
this.fix_date = fix_date;
}
protected Ticket(Parcel in) {
this.ticket_id = in.readInt();
this.name = in.readString();
this.creation_date = in.readString();
this.problem = in.readString();
this.status = in.readString();
this.fix_date = in.readString();
}
public static final Creator<Ticket> CREATOR = new Creator<Ticket>() {
@Override
public Ticket createFromParcel(Parcel in) {
return new Ticket(in);
}
@Override
public Ticket[] newArray(int size) {
return new Ticket[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(ticket_id);
dest.writeString(name);
dest.writeString(creation_date);
dest.writeString(problem);
dest.writeString(status);
dest.writeString(fix_date);
}
public String ticketToString(){
String temp = "";
temp = "Ticket ID: " + ticket_id + "\nCustomer Name: " + name + "\nDate Created: " + creation_date + "\nProblem: " + problem +
"\nStatus: " + status + "\nFix Date:" + fix_date;
return temp;
}
public int getTicketId() {
return ticket_id;
}
public void setTicketId(int ticket_id) {
this.ticket_id = ticket_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCreationDate() {
return creation_date;
}
public void setCreationDate(String creation_date) {
this.creation_date = creation_date;
}
public String getProblem() {
return problem;
}
public void setProblem(String problem) {
this.problem = problem;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getFixDate() {
return fix_date;
}
public void setFixDate(String fix_date) {
this.fix_date = fix_date;
}
}
此票证传递给我的列表票据只是一个可滚动的票证(片段)列表,我可以突出显示并选择编辑或删除。我的问题在于:我知道我必须创建一个动态添加或删除的票证数组列表,但是如何在我们的数组票证列表中传递每个对象的数据时更新和创建一个动态的片段列表?我只想简单地试图绕过一条完成这个的方法。