我试过使用方法putExtra(string name,Serializable object) 添加类调用意图。
致电代码:
package com.example.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import android.location.Address;
import android.os.Parcel;
import android.os.Parcelable;
public class Call implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
//private static final long serialVersionUID = 1L;
static int idCount=1;
int id;
String name;
Address address;
CallStatus status;
ArrayList<SparePart> spareParts;
String caller;
Date callDate;
Technician technician;
ArrayList<String> toDoList;
public Call()
{
}
public Call(CallStatus status, ArrayList<SparePart> spareParts,
String caller, Date callDate, Technician technician,Address address)
{
id=idCount;
idCount++;
this.address=address;
this.status = status;
this.spareParts = spareParts;
this.caller = caller;
this.callDate = callDate;
this.technician = technician;
}
/**
* @return the id
*/
public int getId()
{
return id;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return "Order [id=" + id + ", status=" + status + ", spareParts="
+ spareParts + ", caller=" + caller + ", callDate=" + callDate
+ ", technician=" + technician + "]";
}
/**
* @param id the id to set
*/
public void setId(int id)
{
this.id = id;
}
/**
* @return the status
*/
public CallStatus getStatus()
{
return status;
}
/**
* @param status the status to set
*/
public void setStatus(CallStatus status)
{
this.status = status;
}
/**
* @return the spareParts
*/
public ArrayList<SparePart> getSpareParts()
{
return spareParts;
}
/**
* @param spareParts the spareParts to set
*/
public void setSpareParts(ArrayList<SparePart> spareParts)
{
this.spareParts = spareParts;
}
/**
* @return the caller
*/
public String getCaller()
{
return caller;
}
/**
* @param caller the caller to set
*/
public void setCaller(String caller)
{
this.caller = caller;
}
/**
* @return the callDate
*/
public Date getCallDate()
{
return callDate;
}
/**
* @param callDate the callDate to set
*/
public void setCallDate(Date callDate)
{
this.callDate = callDate;
}
/**
* @return the technicianId
*/
public Technician getTechnicianId()
{
return technician;
}
/**
* @param technicianId the technicianId to set
*/
public void setTechnicianId(Technician technician)
{
this.technician = technician;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return the address
*/
public Address getAddress()
{
return address;
}
/**
* @param address the address to set
*/
public void setAddress(Address address)
{
this.address = address;
}
/**
* @return the technician
*/
public Technician getTechnician()
{
return technician;
}
/**
* @param technician the technician to set
*/
public void setTechnician(Technician technician)
{
this.technician = technician;
}
/**
* @return the toDoList
*/
public ArrayList<String> getToDoList()
{
return toDoList;
}
/**
* @param toDoList the toDoList to set
*/
public void setToDoList(ArrayList<String> toDoList)
{
this.toDoList = toDoList;
}
}
代码SparePart:
package com.example.model;
import java.io.Serializable;
public class SparePart implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 2L;
String description;
float price;
int quantity;
/**
* @return the description
*/
public String getDescription()
{
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return the price
*/
public float getPrice()
{
return price;
}
/**
* @param price the price to set
*/
public void setPrice(float price)
{
this.price = price;
}
/**
* @return the quantity
*/
public int getQuantity()
{
return quantity;
}
/**
* @param quantity the quantity to set
*/
public void setQuantity(int quantity)
{
this.quantity = quantity;
}
}
技术员代码:
package com.example.model;
import java.io.Serializable;
import java.util.ArrayList;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
public class Technician implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 3L;
static int idCount=1;
int id;
String name;
String userName;
String password;
ArrayList<Call> orders;
TechnicianRank rank;
String securityQuestion;
String securityAnswer;
Phone phone;
Email email;
/**
* @return the id
*/
public int getId()
{
return id;
}
/**
* @param id the id to set
*/
public void setId(int id)
{
this.id = id;
}
/**
* @return the userName
*/
public String getUserName()
{
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName)
{
this.userName = userName;
}
/**
* @return the password
*/
public String getPassword()
{
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return the orders
*/
public ArrayList<Call> getOrders()
{
return orders;
}
/**
* @param orders the orders to set
*/
public void setOrders(ArrayList<Call> orders)
{
this.orders = orders;
}
/**
* @return the rank
*/
public TechnicianRank getRank()
{
return rank;
}
/**
* @param rank the rank to set
*/
public void setRank(TechnicianRank rank)
{
this.rank = rank;
}
/**
* @return the securityQuestion
*/
public String getSecurityQuestion()
{
return securityQuestion;
}
/**
* @param securityQuestion the securityQuestion to set
*/
public void setSecurityQuestion(String securityQuestion)
{
this.securityQuestion = securityQuestion;
}
/**
* @return the securityAnswer
*/
public String getSecurityAnswer()
{
return securityAnswer;
}
/**
* @param securityAnswer the securityAnswer to set
*/
public void setSecurityAnswer(String securityAnswer)
{
this.securityAnswer = securityAnswer;
}
/**
* @return the phone
*/
public Phone getPhone()
{
return phone;
}
/**
* @param phone the phone to set
*/
public void setPhone(Phone phone)
{
this.phone = phone;
}
/**
* @return the email
*/
public Email getEmail()
{
return email;
}
/**
* @param email the email to set
*/
public void setEmail(Email email)
{
this.email = email;
}
/**
* @return the name
*/
public String getName()
{
return name;
}
/**
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
}
CallStatus代码:
package com.example.model;
public enum CallStatus
{
Canceled,Open,Done,RequireManagerApprov,SparePartsRequired;
@Override
public String toString() {
switch(this) {
case Canceled: return "Canceled";
case Open: return "Open";
case Done: return "Done";
case RequireManagerApprov: return "RequireManagerApprov";
case SparePartsRequired: return "SparePartsRequired";
default: throw new IllegalArgumentException();
}
}
}
呼唤意图:
Intent intent2 = new Intent(
ShowOrders.this, SpareParts.class);
intent2.putExtra("Call",myList.get(position));
startActivity(intent2);
当myList包含许多Calls instences时。
我试图在没有运气的情况下寻找答案。 有人可以帮我吗???
答案 0 :(得分:0)
我发现这个方法也存在一些问题。
所以你可以把信息放在Bundle
里面
试试这个。
Api是Serializable对象。
private void testBundle() {
Intent intent = new Intent();
Bundle bundle = new Bundle();
intent.setClass(this, FeedActivity.class);//this - Current Activity
bundle.putSerializable("API", api);
intent.putExtras(bundle);
startActivity(intent);
}
从包中获取信息使用下一个代码。
api = (Api) this.getIntent().getExtras().getSerializable("API");