Q:

How to write this anonymous method in one line?

I always bump into these when I do method overloading. How can I write the 2nd method in one line? View.setText(text) returns void, but I want to return the TextView after it executes setText().  Note: I know I can 'write it in two statments'. Question is asking how to make it in one.
private ViewGroup getExpanableListChild() {
    return (LinearLayout) LayoutInflater.from(this).inflate(
            R.layout.list_checkbox, null);
}

private ViewGroup getExpanableListChild(String text) {
    return ViewUtil.getTextViewFromParent(getExpanableListChild()).setText(
            text);//compile error, can't return void.

}

A:

You can use a Builder for these cases but I don't see the point in this particular case.
For example:
return ViewUtil.getTextViewFromParent(getExpanableListChild()) //returns some kind of builder
       .setText(text) // returns builder
       .setColor(someColor) // another example, again returns builder
       .build(); // returns ViewGroup

This is the same strategy present in the SDK where you have an AlertDialog.Builder which builds AlertDialog 

