Only a couple weeks into android, and im a bit stumped. Any and all insight greatly appreciated.
In this code I found, the author is hard coding the values of setOrderName and Status.
I will be pulling these values from a web service though, it looks in here like I would need the o1,o2,o3 objects to increase based on how many records I pull. Is this correct? If so, how would I achieve this.
If im babbling, please feel free to ask for specifics.
Thanks in advance
private void getOrders(){
try{
m_orders = new ArrayList<Order>();
Order o1 = new Order();
o1.setOrderName("SF services");
o1.setOrderStatus("Pending");
Order o2 = new Order();
o2.setOrderName("SF Advertisement");
o2.setOrderStatus("Completed");
m_orders.add(o1);
m_orders.add(o2);
Thread.sleep(5000);
Log.i("ARRAY", ""+ m_orders.size());
} catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
runOnUiThread(returnRes);
}
public class Order {
private String orderName;
private String orderStatus;
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
public String getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(String orderStatus) {
this.orderStatus = orderStatus;
}
}
Multiple
Ordervariables aren’t necessary. Instead of:you can write:
Note the 4 lines that create and add the order use the same local variable,
o.