Background
Google has recently published an update to its support library, which now has a new "SwipeRefreshLayout" view.
The view allows to wrap another view, while supporting swiping down in order to perform a refresh operation.
screenshot:
The problem
Google hasn't provided a sample (at least not one that I can find, yet), so I've tried using it myself.
At first I got a crash (NPE) whenever I swiped, but then I've found out that's because I didn't provide a "OnRefreshListener" for it.
But I still don't get how to use it, let alone customize it
Here's the XML of the layout file:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.swiperefreshlayouttest.MainActivity"
tools:ignore="MergeRootFrame" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Code, though it doesn't do anything special at all:
public class MainActivity extends ActionBarActivity
{
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SwipeRefreshLayout swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.container);
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
// do nothing
}
});
}
}
The question
What is the correct way to use this view?
How do I customize it? Currently it's just a black line...