Android 在活动的每个迭代中添加新的线性布局
在我的一项活动中,我创建了一个线性布局和一些其他小部件,当从Intent接收到一个包时。目前,每次我返回到该活动时,该布局都会被覆盖。如何在不重写代码的情况下每次创建新布局 代码:Android 在活动的每个迭代中添加新的线性布局,android,android-intent,android-linearlayout,Android,Android Intent,Android Linearlayout,在我的一项活动中,我创建了一个线性布局和一些其他小部件,当从Intent接收到一个包时。目前,每次我返回到该活动时,该布局都会被覆盖。如何在不重写代码的情况下每次创建新布局 代码: 听起来您需要创建一个数据结构来保存LinearLayouts,或者为它们提供一个ViewGroup容器,以便每次添加到其中 当前,您正在创建、修改并覆盖try{}catch(){}块中相同的LinearLayout。我猜这就是它不断覆盖的原因。据我所知,您在“最终订单”中添加了新的“选项”。每次添加额外的浇头时,您都
听起来您需要创建一个数据结构来保存LinearLayouts,或者为它们提供一个ViewGroup容器,以便每次添加到其中
当前,您正在创建、修改并覆盖
try{}catch(){}
块中相同的LinearLayout
。我猜这就是它不断覆盖的原因。据我所知,您在“最终订单”中添加了新的“选项”。每次添加额外的浇头时,您都会创建一个布局并用特定数据填充它。您希望它是aka OrderList。如果这个应用程序是关于什么的,你可以有一个应用程序级变量myOrder:List。在FrontPageActivity中添加这些浇头(浇头=新订单())并读取列表。
建议您对订单使用单独的布局。在订单中循环使用数据填充布局,并在活动容器中充气
伪概念:
MyApplication extends Application {
private static List<Order> mOrderList = null;
public MyApplication(){
mOrderList = new ArrayList<Order>();
}
public static List<Order> getOrderList(){
return mOrderList();
}
public static void addOrder(Order order) {
mOrderList.add(order);
}
}
首页活动
foreach(Order order : MyApplication.getOrderList()) {
// fill layout with order data
// inflate orderLayout into container
}
不清楚,试着重写问题。这样更好吗?我的问题是,如果我多次访问活动和try代码块,它会覆盖我创建的linearlayout。我想让它再创造一个。
MyApplication.add(order);
MyApplication.add(order);
foreach(Order order : MyApplication.getOrderList()) {
// fill layout with order data
// inflate orderLayout into container
}