I tried to implement Pull to Refresh in my application.
I wrapped my xml code with android.support.v4.widget.SwipeRefreshLayout and it works, but the GUI does not look very good.
When I pull out, I should see the icon of the usual animated circle with my specific colors, right?, But I see it as an empty circle, and not a rotation with colors, as it should be.
In addition, I can not βplayβ with him and even hold him for a while after I pulled him out, he drops for one second (to do what he does), and then disappears.
I think because I do not use ListView, but LinearLayout instead.
What do you think?
The code:
XML:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/swipe"> <LinearLayout android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:orientation="vertical" android:layout_width="match_parent" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="#7B68EE" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".HomeActivity"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/loin" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/welcome" android:textColor="#B0C4DE" android:id="@+id/welcomeBackID" android:layout_alignParentTop="true" android:layout_alignRight="@+id/webViewCurren" android:layout_alignEnd="@+id/webViewCurren" /> .... </android.support.v4.widget.SwipeRefreshLayout>
Java:
public class HomeActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { SwipeRefreshLayout mSwipeRefreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_green_light, android.R.color.holo_blue_bright, android.R.color.holo_orange_light, android.R.color.holo_red_light); mSwipeRefreshLayout.setOnRefreshListener(this); @Override public void onRefresh() { Toast.makeText(this, "Refresh", Toast.LENGTH_SHORT).show(); sharedPrefEditor.putString("coordinateX", "34.7"); sharedPrefEditor.putString("coordinateY", "32.5"); sharedPrefEditor.putString("saved", "false"); sharedPrefEditor.commit(); new Handler().postDelayed(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(false); } }, 3000); } }
android android-studio listview pull-to-refresh
Json
source share