Android控件ListView优化及数据分页加载

ListView的缓存机制

listView在使用过程中需要注意item view的显示与缓存机制,即屏幕内显示,滑出屏幕就被会收到缓存,避免每次调用getView时都是通过inflate创建一个新的View对象,同时避免又在此view中通过findViewById找到对应的控件,利用ListView的缓存机制实现view的复用。

将数据放入ListView中显示,需要建立数据源与ListView之间的适配关系,也就是需要自定义适配器。

数据源:学生(姓名,班级,年龄)
public class Student {
   
    private String name;
    private String clas;
    private int age;

    public Student(String name, String clas, int age) {
   
        this.name = name;
        this.clas = clas;
        this.age = age;
    }

    public Student(){
   

    }

    public String getName() {
   
        return name;
    }

    public String getClas() {
   
        return clas;
    }

    public int getAge() {
   
        return age;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public void setClas(String clas) {
   
        this.clas = clas;
    }

    public void setAge(int age) {
   
        this.age = age;
    }
}
ListView:样式layout.item_student

在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/tvName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/tvClass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    &
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值