I'm having an issue using SwipeRefreshLayout, the functionality works perfectly but the spinner won't show. I've already used all the provided solutions out there but still nothing.
I don't like to use XML at all so I basically code everything and avoid it. I have a class extending SwipeRefreshLayout where I create the listView, add the adapter and configure the refresh action etc. My minimum API Level is 16.
If you guys need any further details or code please let me know and I'll be glad to provide them, any help is appreciated!
My activity
public class MainActivity extends Activity {
private static MainActivity mainActivity = null;
private MainView mainView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainView = new MainView(this);
setContentView(mainView);
}
public static MainActivity getMainActivity() {
return mainActivity;
}
}
My main view:
public class MainView extends SwipeRefreshLayout {
private ListView listView;
public MainView(Context context) {
super(context);
final String [] objects = new String[] {"panda", "horse", "fox"};
listView = new ListView(context);
final ArrayAdapter arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, objects);
listView.setAdapter(arrayAdapter);
addView(listView);
this.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
objects[0] = "Big panda!";
arrayAdapter.notifyDataSetChanged();
setRefreshing(false);
}
});
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
listView.layout(0, 0, width, height);
}
}