android 表单库SortableTableView详解,详细讲解,帮您上手就用

转载请注明出处:王亟亟的大牛之路

现在各种公司财务流程走到了手机端啊pad这一些产品上面,安卓画类似xls的库并不是太多(可能我见识少),看到一个Git上的库,觉得蛮好用的,尝试性的移植到了产品中去,写一下使用的心得

项目结构
这里写图片描述
实现效果:
这里写图片描述

Gradle:

  compile 'de.codecrafters.tableview:tableview:0.9.5'

最低Minimum SDK-Version: 11 最新版本 0.9.5


如何使用这样的一个tableview?

<de.codecrafters.tableview.TableView
        xmlns:table="http://schemas.android.com/apk/res-auto"
        android:id="@+id/tableView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        table:columnCount="4" />

table:columnCount是你表单的列数,当然需要引入xmlns:table=”http://schemas.android.com/apk/res-auto”

还有其他一些属性,在attributes.xml文件里定义

<resources>
    <declare-styleable name="TableView">
        <attr name="columnCount" format="integer"/>
        <attr name="headerElevation" format="integer"/>
        <attr name="headerColor" format="color"/>
    </declare-styleable>
</resources>

我拿Demo包的代码来作为解释的例子

MainActivity

public class MainActivity extends AppCompatActivity {
   
    //放置数据的容器,每一个对象其实就是等于一行
    private static List<Car> CAR_LIST = new ArrayList<>();


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

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        if (toolbar != null) {
            setSupportActionBar(toolbar);
        }
        //自定义View绑定Id
        SortableCarTableView carTableView = (SortableCarTableView) findViewById(R.id.tableView);
        //填充数据
        carTableView.setDataAdapter(new CarTableDataAdapter(this, CAR_LIST));
        //添加监听事件
        carTableView.addDataClickListener(new CarClickListener());
    }

    //表单内的点触时间,以行为单位
    private class CarClickListener implements TableDataClickListener<Car> {
   

        @Override
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值