創建一個bean
package com.storageproj;
public class myStorage{
private String Name;
private String Count;
private String Amount;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name= Name;
}
public String getCount() {
return Count;
}
public void setCount(String Count) {
this.Count= Count;
}
public String getAmount() {
return Amount;
}
public void setAmount(String Amount) {
this.Amount= Amount;
}
}
你的bean導入到你的主類
import com.storageproj.myStorage;
然後設置你的數據,例如
int Numberofelements = 10;
myStorage = new myStorage[Numberofelements];
for(int i=0;i<Numberofelements;i++){
myStorage [i] = new myStorage();
myStorage.setName("carrot");
myStorage.setCount("3");
myStorage.setAmount("4");
}
,並獲得價值...
import com.storageproj.myStorage;
myStorage[] myStorage;
for the first element...
if (myStorage[0].getName == "carrot"){
Toast.makeText(this, "Carrot, Count= " + myStorage[0].getCount() + ", Amount="+ myStorage[0].getAmount() ,Toast.LENGTH_LONG).show();
}