• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem with ExpandableListView refreshing

karol.k

Lurker
Hi, I have problem with ExpandableListView refreshing. Everything is ok until I click on the list after calling onDataChanged(). I call this method in another class.

Code:
public class OnlineVisitorsView extends ExpandableListActivity{
   MyAdapter adapter;
   
   //SINGLETON
   private static OnlineVisitorsView ourInstance;
   
   public static OnlineVisitorsView getInstance() {
        return ourInstance;
    }
   //END SINGLETON
   
   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ourInstance = this;
        
        adapter = new MyAdapter(this.getBaseContext());
        setListAdapter(adapter);
   }
   
   public void onDataChanged(){
        adapter.getData();
      
   }
}

class MyAdapter extends SimpleExpandableListAdapter{
   
   static List<List<Map<String, Object>>> childData = new ArrayList<List<Map<String, Object>>>();
    static List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
   
   public MyAdapter (Context context)
   {
      super(context,groupData,
              R.layout.grouprow,
              new String[] {"state"},
              new int[] { R.id.groupname },
              childData,
              0,
                null,
                new int[] {}
                );
      getData();

   }
   
   OnlineVisitorsView ovv = OnlineVisitorsView.getInstance();
   
   LayoutInflater layoutInflater = (LayoutInflater) ovv.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   
   
   public void getData(){
      
        
        Map<String, String> onlineClients = new HashMap<String, String>();
        onlineClients.put("state", "Online");
        
        Map<String, String> invitedClients = new HashMap<String, String>();
        invitedClients.put("state", "Invited");
        
        Map<String, String> onChatClients = new HashMap<String, String>();
        onChatClients.put("state", "On chat");
        
        Map<String, String> closedClients = new HashMap<String, String>();
        closedClients.put("state", "Closed");
        
        Map<String, String> offlineClients = new HashMap<String, String>();
        offlineClients.put("state", "Offline");
        
        groupData.add(onlineClients);
        groupData.add(invitedClients);
        groupData.add(closedClients);
        groupData.add(offlineClients);
        
        List<Map<String, Object>> childrenOnline = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> childrenInvited = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> childrenOnChat = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> childrenClosed = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> childrenOffline = new ArrayList<Map<String, Object>>();
        
        Iterator<Client> iterator = OnlineVisitorsDataHandler.clientsList.iterator();
        while (iterator.hasNext()){
       
           Client client = iterator.next();
           
           //Online
           if (client.getState().equals("IWCS1001S")){
              Map<String, Object> currentChildMap = new HashMap<String, Object>();
              
              currentChildMap.put("host", client.getHost());
              currentChildMap.put("country", client.getCountry());
              currentChildMap.put("pageURL", client.getPageURL());
              
              int clientFlagInt = client.getFlag();
              currentChildMap.put("flag", ovv.getResources().getDrawable(clientFlagInt));
              
              int clientBrowserInt = client.getBrowser();
              currentChildMap.put("browser", ovv.getResources().getDrawable(clientBrowserInt));
              
              String keyWords = client.getKeyWords();
              int clientRefererInt = client.getRefererIcon();

              if (!keyWords.equals("")){
                 currentChildMap.put("keyWords", keyWords);
                 currentChildMap.put("refererIcon", ovv.getResources().getDrawable(clientRefererInt));
                 
              }

              childrenOnline.add(currentChildMap);
           }
           
           //Invited
           if (client.getState().equals("IWCS1003S")){
              Map<String, Object> currentChildMap = new HashMap<String, Object>();
              
              currentChildMap.put("host", client.getHost());
              currentChildMap.put("country", client.getCountry());
              currentChildMap.put("pageURL", client.getPageURL());
              
              int clientFlagInt = client.getFlag();
              currentChildMap.put("flag", ovv.getResources().getDrawable(clientFlagInt));
              
              int clientBrowserInt = client.getBrowser();
              currentChildMap.put("browser", ovv.getResources().getDrawable(clientBrowserInt));
              
              String keyWords = client.getKeyWords();
              int clientRefererInt = client.getRefererIcon();

              if (!keyWords.equals("")){
                 currentChildMap.put("keyWords", keyWords);
                 currentChildMap.put("refererIcon", ovv.getResources().getDrawable(clientRefererInt));
                 
              }

              childrenInvited.add(currentChildMap);
           }
           
           //OnChat
           if (client.getState().equals("IWCS1006S")){
              Map<String, Object> currentChildMap = new HashMap<String, Object>();
           
              currentChildMap.put("host", client.getHost());
              currentChildMap.put("country", client.getCountry());
              currentChildMap.put("pageURL", client.getPageURL());
           //   currentChildMap.put("keyWords", client.getReferer());
              
              childrenInvited.add(currentChildMap);
           }
           
           //Closed
           if (client.getState().equals("IWCS1007S")){
              Map<String, Object> currentChildMap = new HashMap<String, Object>();
           
              currentChildMap.put("host", client.getHost());
              currentChildMap.put("country", client.getCountry());
              currentChildMap.put("pageURL", client.getPageURL());
           //   currentChildMap.put("keyWords", client.getReferer());
              
              childrenClosed.add(currentChildMap);
           }
           
           if (client.getState().equals("IWCS1009S")){
              Map<String, Object> currentChildMap = new HashMap<String, Object>();
              
              currentChildMap.put("host", client.getHost());
              currentChildMap.put("country", client.getCountry());
              currentChildMap.put("pageURL", client.getPageURL());
              
              int clientFlagInt = client.getFlag();
              currentChildMap.put("flag", ovv.getResources().getDrawable(clientFlagInt));
              
              int clientBrowserInt = client.getBrowser();
              currentChildMap.put("browser", ovv.getResources().getDrawable(clientBrowserInt));
              
              String keyWords = client.getKeyWords();
              int clientRefererInt = client.getRefererIcon();

              if (!keyWords.equals("")){
                 currentChildMap.put("keyWords", keyWords);
                 currentChildMap.put("refererIcon", ovv.getResources().getDrawable(clientRefererInt));
                 
              }

              childrenOffline.add(currentChildMap);
           }
           
        }
        
        childData.add(childrenOnline);
        childData.add(childrenInvited);
        childData.add(childrenClosed);
        childData.add(childrenOffline);

   }
   
   
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
         final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);

         // Populate your custom view here
         ((TextView)v.findViewById(R.id.hostname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("host") );
         ((TextView)v.findViewById(R.id.country)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("country") );
         ((TextView)v.findViewById(R.id.pageURL)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("pageURL") );
         ((TextView)v.findViewById(R.id.keyWords)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("keyWords") );
         ((ImageView)v.findViewById(R.id.countryFlag)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("flag") );
         ((ImageView)v.findViewById(R.id.browserIcon)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("browser") );
         ((ImageView)v.findViewById(R.id.refererIcon)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("refererIcon") );
         
         return v;
    }

    public View newChildView(boolean isLastChild, ViewGroup parent) {
          return layoutInflater.inflate(R.layout.childrow, null, false);
    }
    
        
}

Exception

Code:
Thread [<1> main] (Suspended (exception IllegalStateException))   
   ExpandableListView(ListView).layoutChildren() line: 1662   
   AbsListView$CheckForTap.run() line: 1884   
   ViewRoot(Handler).handleCallback(Message) line: 587   
   ViewRoot(Handler).dispatchMessage(Message) line: 92   
   Looper.loop() line: 123   
   ActivityThread.main(String[]) line: 4627   
   Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]   
   Method.invoke(Object, Object...) line: 521   
   ZygoteInit$MethodAndArgsCaller.run() line: 868   
   ZygoteInit.main(String[]) line: 626   
   NativeStart.main(String[]) line: not available [native method]

Can anybody help me?
 
Back
Top Bottom