最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android SwipeRefreshLayout仿抖音app静态刷新的教程
时间:2022-06-25 23:03:03 编辑:袖梨 来源:一聚教程网
SwipeRefreshLayout的功能就是可以让我们的界面在不动的情况下,下拉直接刷新
废话不多说,效果图奉上:
activity_listview布局文件
Activity代码(ListViewActivity)
public class ListViewActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
private SwipeRefreshLayout swipeRefreshLayout;
private ListView listView;
private List 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);
}
}
相关文章
- NPC精神是什么 - 当代年轻人的社交状态解读 06-11
- 末世崛起钻石怎么获得 06-11
- 缤果盒子2026年最新招聘信息 - 全国热门岗位持续招聘中 06-11
- 大奉打更人职业体系有什么 06-11
- 生存33天平民如何搭配阵容 06-11
- Claude开发者免费替代工具怎么选?3款开源模型对比 06-11
