TheGame TimeMachine
TheGame TimeMachine

Reputation: 75

Android Async inside a OnGroupClickListener function

I have a Exapandable Listview that needs the child rows to be added dynamically when someone clicks on a group row. Best way was to send a AsyncHttp request to my server and the server responds with a json which I parse into and Object. The problem with this is that I need to return true on the OnClickGroupListener if json is empty and or false if json has data. How would I go bout doing this?

UPDATE*******

I added the Following to my code:

    private boolean childrenLoaded;
 public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
            if(!childrenLoaded){
                getChildren(i);
            }else{
              return false;
            }
           return true;
        }

public void getChildren(int position){
    //HttpAsync request here
    onSuccess(json){
        childrenLoaded = true;
        if (json has data){
        listview.performclick(arguments for perform click);
        }else{
        exit
        }
    }

}

Upvotes: 1

Views: 66

Answers (1)

Collin Flynn
Collin Flynn

Reputation: 771

Looking at the OnGroupClickListener documentation, it appears you only need to return true if the click was handled by you.

Returns

True if the click was handled

If you would like to track some other true/false outcome (such as the emptyness of a json response) it should conceptually and literally be handled elsewhere. For example, you could have a small progress indicator that shows on the list item when the click happens (return true because you obviously handled the click), and stop the progress bar when your network request completes with either a success or a failure.

Upvotes: 1

Related Questions