2017-03-29 5 views
-2

私のアプリでインターネットからの情報を更新するためにそれをコード化する方法を誰も知っていますか? Like this画面をプルダウンすると更新されます。アンドロイド

お返事ありがとうございます!

+2

androiのSwipeRefreshLayout thatsネイティブ – g7pro

+0

本当にしたいですか? UIをリフレッシュするようにしますか? –

+1

[SwipeRefreshLayoutの使い方?](http://stackoverflow.com/questions/23014846/how-to-use-the-swiperefreshlayout)の可能な複製 –

答えて

0

ステップ1:あなたのレイアウトファイルにコードを貼り付け

<android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_refresh_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 


     <ListView 
      android:smoothScrollbar="true" 
      android:id="@+id/mListView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:visibility="gone" /> 
    </android.support.v4.widget.SwipeRefreshLayout> 

ステップ2:あなたのJavaファイルを開き、これらの行を追加します。

public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener 
     private SwipeRefreshLayout swipeRefreshLayout; 


     public void onCreate(Bundle savedStateInstances){ 
     .... 
     swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); 
    swipeRefreshLayout.setOnRefreshListener(this); 

     } 

    @Override 
    public void onRefresh() { 


     //implement the logic you want to do when the pull down happen. 

//after completion of your logic add this line. 
swipeRefreshLayout.setRefreshing(false); 
    } 
0

必要なものはPull to Refreshです。周囲に例があります。 thisを確認してください。ここで

1

例implemantationです:

<android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/container_items" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:background="@color/white" 
     > 

     <ListView 
      android:id="@+id/list_recent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      /> 

    </android.support.v4.widget.SwipeRefreshLayout> 

次に作成上のクラスに:その後、

 mItemsContainer = (SwipeRefreshLayout) findViewById(R.id.container_items); 
    mItemsContainer.setOnRefreshListener(this); 

クラスのいくつかの場所:

@Override 
    public void onRefresh() { 

     // after refresh code 
    } 
0

使用

としてSTEP1ようSwipeRefreshLayout:xmlファイル

<android.support.v4.widget.SwipeRefreshLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/swipe_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:text="@string/hello_world" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:gravity="center"/> 
</ScrollView> 
</android.support.v4.widget.SwipeRefreshLayout> 

STEP2を作る:あなたの活動で行うこの

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); 
swipeLayout.setOnRefreshListener(this); 
swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
     android.R.color.holo_green_light, 
     android.R.color.holo_orange_light, 
     android.R.color.holo_red_light); 
} 
@Override 
public void onRefresh() { 
new Handler().postDelayed(new Runnable() { 
    @Override public void run() { 
     swipeLayout.setRefreshing(false); 
    } 
}, 5000); 
} 
関連する問題