首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含ListView的ListView

包含ListView的ListView
EN

Stack Overflow用户
提问于 2013-06-10 23:23:54
回答 2查看 453关注 0票数 0

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

下面是我展示第一个listView的方法:

代码语言:javascript
复制
    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,它是可以的,但由于末尾的行(使用第二个适配器**)失败。我不知道我能不能再用一个这样的适配器...

我怎么能做到这一点?

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2013-06-11 15:41:41

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

Creating LinearLayout in Java - Elements are not shown

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

票数 0
EN

Stack Overflow用户

发布于 2013-06-11 15:56:35

为什么不使用呢?

将一个ListView嵌套在另一个中可能会被证明是非常麻烦的。特别是处理子进程和父进程中的滚动事件。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17027362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档