Problem with ExpandableListView refreshing


Last Updated:

  1. karol.k

    karol.k New Member This Topic's Starter

    Joined:
    Aug 27, 2010
    Messages:
    1
    Likes Received:
    0
    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 (Text):
    1. public class OnlineVisitorsView extends ExpandableListActivity{
    2.    MyAdapter adapter;
    3.    
    4.    //SINGLETON
    5.    private static OnlineVisitorsView ourInstance;
    6.    
    7.    public static OnlineVisitorsView getInstance() {
    8.         return ourInstance;
    9.     }
    10.    //END SINGLETON
    11.    
    12.    public void onCreate(Bundle savedInstanceState) {
    13.         super.onCreate(savedInstanceState);
    14.         ourInstance = this;
    15.        
    16.         adapter = new MyAdapter(this.getBaseContext());
    17.         setListAdapter(adapter);
    18.    }
    19.    
    20.    public void onDataChanged(){
    21.         adapter.getData();
    22.      
    23.    }
    24. }
    25.  
    26. class MyAdapter extends SimpleExpandableListAdapter{
    27.    
    28.    static List<List<Map<String, Object>>> childData = new ArrayList<List<Map<String, Object>>>();
    29.     static List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    30.    
    31.    public MyAdapter (Context context)
    32.    {
    33.       super(context,groupData,
    34.               R.layout.grouprow,
    35.               new String[] {"state"},
    36.               new int[] { R.id.groupname },
    37.               childData,
    38.               0,
    39.                 null,
    40.                 new int[] {}
    41.                 );
    42.       getData();
    43.  
    44.    }
    45.    
    46.    OnlineVisitorsView ovv = OnlineVisitorsView.getInstance();
    47.    
    48.    LayoutInflater layoutInflater = (LayoutInflater) ovv.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    49.    
    50.    
    51.    public void getData(){
    52.      
    53.        
    54.         Map<String, String> onlineClients = new HashMap<String, String>();
    55.         onlineClients.put("state", "Online");
    56.        
    57.         Map<String, String> invitedClients = new HashMap<String, String>();
    58.         invitedClients.put("state", "Invited");
    59.        
    60.         Map<String, String> onChatClients = new HashMap<String, String>();
    61.         onChatClients.put("state", "On chat");
    62.        
    63.         Map<String, String> closedClients = new HashMap<String, String>();
    64.         closedClients.put("state", "Closed");
    65.        
    66.         Map<String, String> offlineClients = new HashMap<String, String>();
    67.         offlineClients.put("state", "Offline");
    68.        
    69.         groupData.add(onlineClients);
    70.         groupData.add(invitedClients);
    71.         groupData.add(closedClients);
    72.         groupData.add(offlineClients);
    73.        
    74.         List<Map<String, Object>> childrenOnline = new ArrayList<Map<String, Object>>();
    75.         List<Map<String, Object>> childrenInvited = new ArrayList<Map<String, Object>>();
    76.         List<Map<String, Object>> childrenOnChat = new ArrayList<Map<String, Object>>();
    77.         List<Map<String, Object>> childrenClosed = new ArrayList<Map<String, Object>>();
    78.         List<Map<String, Object>> childrenOffline = new ArrayList<Map<String, Object>>();
    79.        
    80.         Iterator<Client> iterator = OnlineVisitorsDataHandler.clientsList.iterator();
    81.         while (iterator.hasNext()){
    82.        
    83.            Client client = iterator.next();
    84.            
    85.            //Online
    86.            if (client.getState().equals("IWCS1001S")){
    87.               Map<String, Object> currentChildMap = new HashMap<String, Object>();
    88.              
    89.               currentChildMap.put("host", client.getHost());
    90.               currentChildMap.put("country", client.getCountry());
    91.               currentChildMap.put("pageURL", client.getPageURL());
    92.              
    93.               int clientFlagInt = client.getFlag();
    94.               currentChildMap.put("flag", ovv.getResources().getDrawable(clientFlagInt));
    95.              
    96.               int clientBrowserInt = client.getBrowser();
    97.               currentChildMap.put("browser", ovv.getResources().getDrawable(clientBrowserInt));
    98.              
    99.               String keyWords = client.getKeyWords();
    100.               int clientRefererInt = client.getRefererIcon();
    101.  
    102.               if (!keyWords.equals("")){
    103.                  currentChildMap.put("keyWords", keyWords);
    104.                  currentChildMap.put("refererIcon", ovv.getResources().getDrawable(clientRefererInt));
    105.                  
    106.               }
    107.  
    108.               childrenOnline.add(currentChildMap);
    109.            }
    110.            
    111.            //Invited
    112.            if (client.getState().equals("IWCS1003S")){
    113.               Map<String, Object> currentChildMap = new HashMap<String, Object>();
    114.              
    115.               currentChildMap.put("host", client.getHost());
    116.               currentChildMap.put("country", client.getCountry());
    117.               currentChildMap.put("pageURL", client.getPageURL());
    118.              
    119.               int clientFlagInt = client.getFlag();
    120.               currentChildMap.put("flag", ovv.getResources().getDrawable(clientFlagInt));
    121.              
    122.               int clientBrowserInt = client.getBrowser();
    123.               currentChildMap.put("browser", ovv.getResources().getDrawable(clientBrowserInt));
    124.              
    125.               String keyWords = client.getKeyWords();
    126.               int clientRefererInt = client.getRefererIcon();
    127.  
    128.               if (!keyWords.equals("")){
    129.                  currentChildMap.put("keyWords", keyWords);
    130.                  currentChildMap.put("refererIcon", ovv.getResources().getDrawable(clientRefererInt));
    131.                  
    132.               }
    133.  
    134.               childrenInvited.add(currentChildMap);
    135.            }
    136.            
    137.            //OnChat
    138.            if (client.getState().equals("IWCS1006S")){
    139.               Map<String, Object> currentChildMap = new HashMap<String, Object>();
    140.            
    141.               currentChildMap.put("host", client.getHost());
    142.               currentChildMap.put("country", client.getCountry());
    143.               currentChildMap.put("pageURL", client.getPageURL());
    144.            //   currentChildMap.put("keyWords", client.getReferer());
    145.              
    146.               childrenInvited.add(currentChildMap);
    147.            }
    148.            
    149.            //Closed
    150.            if (client.getState().equals("IWCS1007S")){
    151.               Map<String, Object> currentChildMap = new HashMap<String, Object>();
    152.            
    153.               currentChildMap.put("host", client.getHost());
    154.               currentChildMap.put("country", client.getCountry());
    155.               currentChildMap.put("pageURL", client.getPageURL());
    156.            //   currentChildMap.put("keyWords", client.getReferer());
    157.              
    158.               childrenClosed.add(currentChildMap);
    159.            }
    160.            
    161.            if (client.getState().equals("IWCS1009S")){
    162.               Map<String, Object> currentChildMap = new HashMap<String, Object>();
    163.              
    164.               currentChildMap.put("host", client.getHost());
    165.               currentChildMap.put("country", client.getCountry());
    166.               currentChildMap.put("pageURL", client.getPageURL());
    167.              
    168.               int clientFlagInt = client.getFlag();
    169.               currentChildMap.put("flag", ovv.getResources().getDrawable(clientFlagInt));
    170.              
    171.               int clientBrowserInt = client.getBrowser();
    172.               currentChildMap.put("browser", ovv.getResources().getDrawable(clientBrowserInt));
    173.              
    174.               String keyWords = client.getKeyWords();
    175.               int clientRefererInt = client.getRefererIcon();
    176.  
    177.               if (!keyWords.equals("")){
    178.                  currentChildMap.put("keyWords", keyWords);
    179.                  currentChildMap.put("refererIcon", ovv.getResources().getDrawable(clientRefererInt));
    180.                  
    181.               }
    182.  
    183.               childrenOffline.add(currentChildMap);
    184.            }
    185.            
    186.         }
    187.        
    188.         childData.add(childrenOnline);
    189.         childData.add(childrenInvited);
    190.         childData.add(childrenClosed);
    191.         childData.add(childrenOffline);
    192.  
    193.    }
    194.    
    195.    
    196.     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    197.          final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
    198.  
    199.          // Populate your custom view here
    200.          ((TextView)v.findViewById(R.id.hostname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("host") );
    201.          ((TextView)v.findViewById(R.id.country)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("country") );
    202.          ((TextView)v.findViewById(R.id.pageURL)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("pageURL") );
    203.          ((TextView)v.findViewById(R.id.keyWords)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("keyWords") );
    204.          ((ImageView)v.findViewById(R.id.countryFlag)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("flag") );
    205.          ((ImageView)v.findViewById(R.id.browserIcon)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("browser") );
    206.          ((ImageView)v.findViewById(R.id.refererIcon)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get("refererIcon") );
    207.          
    208.          return v;
    209.     }
    210.  
    211.     public View newChildView(boolean isLastChild, ViewGroup parent) {
    212.           return layoutInflater.inflate(R.layout.childrow, null, false);
    213.     }
    214.    
    215.        
    216. }
    Exception

    Code (Text):
    1. Thread [<1> main] (Suspended (exception IllegalStateException))  
    2.    ExpandableListView(ListView).layoutChildren() line: 1662  
    3.    AbsListView$CheckForTap.run() line: 1884  
    4.    ViewRoot(Handler).handleCallback(Message) line: 587  
    5.    ViewRoot(Handler).dispatchMessage(Message) line: 92  
    6.    Looper.loop() line: 123  
    7.    ActivityThread.main(String[]) line: 4627  
    8.    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    9.    Method.invoke(Object, Object...) line: 521  
    10.    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    11.    ZygoteInit.main(String[]) line: 626  
    12.    NativeStart.main(String[]) line: not available [native method]
    Can anybody help me?
     

    Advertisement

Share This Page

Loading...