Android SwipeRefreshLayout 모 의 틱 톡 앱 정적 새로 고침

2140 단어 Android떨 음app
Swipe RefreshLayout 의 기능 은 바로 우리 의 인터페이스 가 움 직 이지 않 는 상황 에서 아래로 당 겨 서 바로 갱신 할 수 있 도록 하 는 것 이다.
쓸데없는 말 을 많이 하지 않 으 면 효과 도 드 립 니 다.

activity_listview 레이아웃 파일

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/sr1" 
    android:layout_width="match_parent" 
   android:layout_height="match_parent"> 
    <ListView 
     android:id="@+id/lv" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
   </android.support.v4.widget.SwipeRefreshLayout> 
활동 코드(ListViewActivity)

public class ListViewActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { 
 private SwipeRefreshLayout swipeRefreshLayout; 
 private ListView listView; 
 private List<String> list; 
 private ArrayAdapter adapter; 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_list_view); 
  swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.sr1); 
  swipeRefreshLayout.setOnRefreshListener(this); 
  list = new ArrayList<>(); 
  list.add("ssss"); 
  listView = (ListView) findViewById(R.id.lv); 
  adapter = new ArrayAdapter(this 
    , android.R.layout.simple_list_item_1 
    , android.R.id.text1 
    , list); 
  listView.setAdapter(adapter); 
 } 
 
 @Override 
 public void onRefresh() { 
  new Handler().postDelayed(new Runnable() { 
   @Override 
   public void run() { 
    swipeRefreshLayout.setRefreshing(false); 
    adapter.clear(); 
    list.add("1111"); 
    adapter.notifyDataSetChanged(); 
   } 
  }, 1000); 
 } 
} 


이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기