0

我需要显示一个包含另一个 listView 的 listView。

这是我显示第一个 listView 的方法:

    public class myClas extends ListActivity {

        private List<Order> listOrders = new ArrayList<Order>();
        private ArrayList<HashMap<String, String>> orderList, orderItems;
        private ProgressDialog pDialog;

        /**
         * First method called when the activity is created
         * @param Bundle savedInstanceState contains the backup status recorded during the last execution of the activity
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_historic);

            //hashmap
            orderList = new ArrayList<HashMap<String, String>>();
            orderItems = new ArrayList<HashMap<String, String>>();

            //loading in the background
            new LoadingOrders().execute();
        }

        /**
         * Loading orders in the background
         * */
        class LoadingOrders extends AsyncTask<String, String, String> {

            /**
             * Before starting the thread in the background, a progress bar is displayed
             * */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(Historic.this);
                pDialog.setMessage("Loading");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
            }

            /**
             * Retrieving orders
             * */
            @Override
            protected String doInBackground(String... args) {
//the first listView                
for (int i = 0; i < listOrders.size(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    map.put("date", "date_exemple);
                    orderList.add(map);

//the second listView  
                    for (int j = 0; j < order.getOrderItems().size(); j++) {
                        HashMap<String, String> mapItems = new HashMap<String, String>();

                        mapItems.put("textViewPrice", "price_exemple"));
                        mapItems.put("textViewStatus", "status_example");
                        orderList.add(map);
                    }
                }
                return null;
            }

            /**
             * After completing the background tasks, remove the progress bar
             * **/
            @Override
            protected void onPostExecute(String file_url) {
                //The progress bar is removed
                pDialog.dismiss();
                // Update the user interface
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
//the first listView  
                        //Updating orders
                        ListAdapter adapter = new SimpleAdapter(
                                MyClass.this, orderList,
                                R.layout.order, new String[] { "date"},
                                new int[] { R.id.textViewDate});
                        setListAdapter(adapter);

//the second listView  
                        //OrderItems
                        **adapter = new SimpleAdapter(
                                MyClass.this, orderItems,
                                R.layout.order_item, new String[] { "textViewPrice", "textViewStatus"},
                                new int[] { R.id.textViewPrice, R.id.textViewStatus});
                        setListAdapter(adapter);**
                    }
                });

            }

        }
    }

对于第一个 listView,没关系,但是最后的行(带有第二个适配器 **)它失败了。我不知道我是否可以使用这样的第二个适配器...

我怎么能这样做?

谢谢。

4

2 回答 2

0

对于行中的班轮布局,我可以使用这个吗?

在 Java 中创建 LinearLayout - 不显示元素

但是,在这段代码的末尾,我不能执行 setContentView(layout),因为包含我的列表的布局将会消失。那么我该怎么做呢?

于 2013-06-11T07:41:40.690 回答
0

你为什么不使用ExpandableListView

将一个 ListView 嵌套在另一个 ListView 中可能会非常麻烦。特别是处理子级和父级内部的滚动事件。

是的,这可能不是不可能的,但为什么要让你的生活变得艰难呢?

于 2013-06-11T07:56:34.633 回答