转载请注明出处:王亟亟的大牛之路
现在各种公司财务流程走到了手机端啊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