Android Forums

Go Back   Android Forums > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Display Modes
Old 08-27-2010, 04:01 AM   #1
New Member
 
Join Date: Aug 2010
Posts: 1
Friends: 0
View karol.k's Profile   View karol.k's Photo Album   View karol.k's Blog   View Social Groups
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]
karol.k is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes




Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 10:22 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.