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 では問題ありませんが、最後の行 (2 番目のアダプター **) では失敗します。このような2番目のアダプターを使用できるかどうかはわかりません...

どうすればそれができますか?

ありがとう。

4

2 に答える 2

0

ライナーを一列にレイアウトする場合、これを使用できますか?

Java で LinearLayout を作成する - 要素が表示されない

しかし、このコードの最後では、リストを含むレイアウトが消えるため、setContentView(layout) を実行できません。では、どうすればそれを行うことができますか?

于 2013-06-11T07:41:40.690 に答える
0

ExpandableListViewを使用しないのはなぜですか?

1 つの ListView を別の ListView 内にネストすると、非常に面倒になる場合があります。特に、子と親の中でスクロール イベントを処理します。

はい、不可能ではないかもしれませんが、なぜあなたの人生を困難にするのですか?

于 2013-06-11T07:56:34.633 に答える