Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 15th, 2012  |  syntax: None  |  size: 2.07 KB  |  views: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. expListAdapter = new MyListAdapter(this, createGroupList(), createGroupList());
  2. setListAdapter( expListAdapter );
  3.        
  4. private List createGroupList() {    
  5.       ArrayList result = new ArrayList();
  6.       for (int i=0; i < Liste.AnzahlElemente(); i++) {    //
  7.         result.add(Liste.getSize(i).getGroupString());
  8.       }
  9.       return result;
  10.     }
  11.  
  12.     private List createChildList() {
  13.         ArrayList result = new ArrayList();
  14.         for(int i=0; i < Liste.getSize(); i++) {
  15.             ArrayList secList = new ArrayList();
  16.             for( int n = 1 ; n <= 3 ; n++ ) {
  17.                 if (Liste.getElement(i).getChildString(n).length() != 0){
  18.                     secList.add( "- " + Liste.getElement(i).getChildString(n));
  19.                 }
  20.             }
  21.             result.add( secList );
  22.         }
  23.         return result;
  24. }
  25.        
  26. Collections.sort(Liste.getListe(), new NameComparator());
  27.  
  28. expListAdapter.notifyDataSetInvalidated();
  29.  
  30. //expListAdapter.notifyDataSetChanged(); //same effect as notifyDataSetInvalided
  31.        
  32. public class NameComparator implements Comparator<ToDoElement>{
  33.  
  34.      public int compare(ToDoElement item1, ToDoElement item2) {
  35.            return item1.getGroupString().compareTo(item2.getGroupString());
  36.      }
  37. }
  38.        
  39. public class MyListAdapter extends BaseExpandableListAdapter{
  40.  
  41.      private ArrayList<String> ueberschriften;
  42.      private ArrayList<ArrayList<String>> stichpunkte;
  43.  
  44.      public MyListAdapter(Context context, List _ueberschriften, List _stichpunkte) {
  45.  
  46.           this.ueberschriften = (ArrayList)_ueberschriften;
  47.           this.stichpunkte = (ArrayList)_stichpunkte;
  48.  
  49.           inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  50.     }
  51.  
  52.      // [...] some other methods
  53.  
  54.      public void update(List _GroupStrings, List _ChildStrings) {
  55.           GroupStrings = (ArrayList<String>) _GroupStrings;
  56.           ChildStrings = (ArrayList<ArrayList<String>>) _ChildStrings;
  57.      }
  58. }
  59.        
  60. Collections.sort(Liste.getListe(), new NameComparator());
  61.  
  62. expListAdapter.update(createGroupList(), createChildList());
  63.  
  64. expListAdapter.notifyDataSetChanged();
clone this paste RAW Paste Data