Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Implementing Designs for Android Customizing a ListView for the Inbox Adding a Swipe-to-Refresh Gesture

Javier Briones
seal-mask
.a{fill-rule:evenodd;}techdegree
Javier Briones
Front End Web Development Techdegree Student 29,674 Points

Adding a swipe-to-refresh gesture task 3 of 4

Hello, I've been trying and trying but I just can't figure out this code challenge. Here's my code:

import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;

public class MainActivity extends ListActivity {

/*
 * Some code has been omitted for brevity
 */

public SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.refreshLayout); mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public OnRefreshListener mOnRefreshListener = new OnRefreshListener() {
    @Override
    public void onRefresh() {
        // Code that refreshes the content in the layout...

    }
}; 

}

And here's the error that I get:

./MainActivity.java:11: expected mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ ./MainActivity.java:11: expected mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ ./MainActivity.java:11: cannot find symbol symbol : class mOnRefreshListener location: class MainActivity mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ ./MainActivity.java:11: package mSwipeRefreshLayout does not exist mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ JavaTester.java:72: cannot find symbol symbol : variable mRefreshLayout location: class MainActivity else if (activity.mRefreshLayout == null) { ^ JavaTester.java:83: cannot find symbol symbol : variable mRefreshLayout location: class MainActivity if (activity.mRefreshLayout.isWrongListenerUsed) { ^ JavaTester.java:86: cannot find symbol symbol : variable mRefreshLayout location: class MainActivity else if (!activity.mRefreshLayout.isSetOnRefreshListenerCalled) { ^ 7 errors

Timothy Boland
Timothy Boland
18,237 Points

Did you figure it out Javier? Or are you still stuck?

3 Answers

Timothy Boland
Timothy Boland
18,237 Points
 mRefreshLayout.setOnRefreshListener(mOnRefreshListener);

Finally i figure out this problem method must be call in oncreate()

I got same issue

                       import android.os.Bundle;
                       import android.support.v4.widget.SwipeRefreshLayout;
                            import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;

public class MainActivity extends ListActivity {
public SwipeRefreshLayout mRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.refreshLayout);
 mRefreshLayout.setOnRefreshListener(mOnRefreshListener);
    /*
     * Some code has been omitted for brevity
     */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public OnRefreshListener mOnRefreshListener = new OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Code that refreshes the content in the layout...
        }
    }; 
}