Marie Amida Marie Amida - 3 months ago 19
Android Question

SwipeRefreshLayout with Spinner

I have been trying to implement the functionality of the SwipeRefreshLayout for my Spinner, but nothing is happening. Does anybody have an idea why is this not working? The Spinner is loading the data the first time without a problem, but when I do the dragging gesture, nothing is happening. No colours, no spinning, no System.out.println, nothing :(

Here is my XML and Java code.

XML

<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="0dp"
android:layout_height="44dp"
android:id="@+id/swipe_main">
<Spinner
android:id="@+id/data_spinner"
android:layout_width="0dp"
android:layout_height="44dp"/>
</android.support.v4.widget.SwipeRefreshLayout>


JAVA

spinner = (Spinner) findViewById(R.id.data_spinner);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, dataArrayList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);

swipe = (SwipeRefreshLayout) findViewById(R.id.swipe_main);
swipe.setColorSchemeColors(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
adapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item,dataArrayList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
swipe.setRefreshing(false);
System.out.println("Is swipe refreshing?...");

}
});


Thanks a lot in advance!

sJy sJy
Answer

SwipeRefreshLayout works when swiping on its Child Views.

In your case, when Spinner is Clicked, it opens the list as DropdownPopup which is a subclass of ListPopupWindow. It is not the child view of SwipeRefreshLayout but a popup window & hence swipe doesn't work. But it works if you swipe over the Spinner when dropdown is not opened.