Мне нужно отобразить listView, содержащий другой listView.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, это нормально, но с линиями в конце (со вторым адаптером **) он терпит неудачу. Я не знаю, могу ли я использовать второй адаптер, подобный этому ...
Как я могу это сделать?
Спасибо.
это плохая идея провести один список в другом, попробуйте один список со многими линейными макетами в строке вместо. –
Древовидная идея, но не невозможно? в противном случае, как я могу это сделать с linerlayouts в строке? – user2021346
У вас будут проблемы с двумя полосами прокрутки одновременно, рассмотрите возможность использования expandablelistview. – AlexBcn