我需要显示一个包含另一个 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,没关系,但是最后的行(带有第二个适配器 **)它失败了。我不知道我是否可以使用这样的第二个适配器...
我怎么能这样做?
谢谢。