Methods aren't having an effect on a SwipeRefreshLayout

199
March 11, 2017, at 10:49 AM

Every method I use on the SwipeRefreshLayout doesn't have an effect on it. I have quite new to Java, so it might have been how I have been defining my variables.

Here is my onCreate():

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences pref = getSharedPreferences("application_settings", MODE_PRIVATE);
        Boolean darkTheme = (pref.getBoolean("DarkTheme", false));
        if(darkTheme == false){
           setTheme(R.style.AppTheme);
        }
        else{
           setTheme(R.style.DarkAppTheme);
        }
        setContentView(R.layout.activity_main);
        .
        .
        .
       final SwipeRefreshLayout test = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
        if (darkTheme == true) {
            test.setColorSchemeResources(R.color.grey_check);
        }
        else{
            test.setColorSchemeResources(R.color.colorPrimary);
        }
        test.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                test.setRefreshing(true);
                OnSwipe();
            }
        });
   }

and here is my OnSwipe() method:

public void OnSwipe(){
      mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
      .
      . // Some data processing
      .       
      mRefreshLayout.setRefreshing(false);

Whenever I use a method to affect its state, nothing happens except for the icon to show up. It will not stop showing the refresh icon.

Answer 1

edit: I read your question quickly 5 mins ago, I edit the answer:

You should set this as global variable:

SwipeRefreshLayout test;

then in onCreate(), set it like this:

test = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);

after these 2 steps, you can use it like this:

test.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            test.setRefreshing(true);
            OnSwipe();
        }
    });

and onSwipe():

public void OnSwipe(){
  .
  . // Some data processing
  .       
  test.setRefreshing(false);
}
READ ALSO
Sharedpreferences not saved

Sharedpreferences not saved

I have tried all the possible solution given in other answers about shared preference, and still was not able to solve, thus made this question

301
Set logo size in Firebase UI

Set logo size in Firebase UI

Is there anyway to set the size of the logo in Firebase UI so it doesn't completely fill the view?

407
Android system killed my service when I clear all recent app, or run ram cleaner application

Android system killed my service when I clear all recent app, or run ram cleaner application

I want to make an application that always runs a serviceHowever, when I run a RAM cleaner tool, my application gets closed

228
MP Android Chart “Table” on XAxis (Custom Renderer for XAxis)

MP Android Chart “Table” on XAxis (Custom Renderer for XAxis)

Hello I wan't to know if this kind of graphics are possible using MP Android Chart:

316