AdaptiveTableLayout
介绍:
一个可以阅读与编辑CSV文件的库。
运行效果:
使用说明:
gradle :
dependencies {
compile "com.cleveroad:adaptivetablelayout:1.0.1"
}
特性
Library 由三部分组成:
-
AdaptiveTableLayout (View)
-
LinkedAdaptiveTableAdapter (Adapter)
-
ViewHolderImpl (ViewHolder)
AdaptiveTableLayout
<com.cleveroad.adaptivetablelayout.AdaptiveTableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cellMargin="1dp"
app:fixedHeaders="true"
app:solidRowHeaders="true" />
属性 | 描述 |
---|---|
cellMargin | margin between cards |
fixedHeaders | fixed headers mode. If enable, headers always will be displayed in the corners. |
solidRowHeaders | solid row headers mode. If enable, row header will change its position with dragging row. |
// return fixed headers mode
boolean isHeaderFixed();
// return solid row headers mode
boolean isSolidRowHeader()
// Set fixed headers mode
void setHeaderFixed(boolean headerFixed)
// Set solid row headers mode
void setSolidRowHeader(boolean solidRowHeader)
/**
* Set adapter with IMMUTABLE data.
* Create wrapper with links between layout rows, columns and data rows, columns.
* On drag and drop event just change links but not change data in adapter.
*/
void setAdapter(@Nullable AdaptiveTableAdapter adapter)
/**
* Set adapter with MUTABLE data.
* You need to implement switch rows and columns methods.
* DO NOT USE WITH BIG DATA!!
*/
void setAdapter(@Nullable DataAdaptiveTableLayoutAdapter adapter)
// Notify any registered observers that the data set has changed.
void notifyDataSetChanged()
// Notify any registered observers that the item has changed.
void notifyItemChanged(int rowIndex, int columnIndex)
// Notify any registered observers that the row with rowIndex has changed.
void notifyRowChanged(int rowIndex)
// Notify any registered observers that the column with columnIndex has changed.
void notifyColumnChanged(int columnIndex)
Adapter
你可以使用adapter接口:AdaptiveTableAdapter and DataAdaptiveTableLayoutAdapter。但是为了简化用法,库中包含了base adapters:BaseDataAdaptiveTableLayoutAdapter 和 LinkedAdaptiveTableAdapter。
BaseDataAdaptiveTableLayoutAdapter - 适用于轻量级数据的简单simple adapter。 警告! 改变列和行顺序的时候,原始数据会发生改变。
LinkedAdaptiveTableAdapter -适用于重量级数据的adapter。警告!这种类型的adapter不会改变原始数据。它包含了被改变item的link。要让数据发生变化的话,需要使用AdaptiveTableLayout.getLinkedAdapterRowsModifications() 以及AdaptiveTableLayout.getLinkedAdapterColumnsModifications()。别忘了检查AdaptiveTableLayout.isSolidRowHeader() flag,如果为false,你需要忽略每行的第一个元素。
For both adapters you need to know all rows/columns widths, heights and rows/columns count before set adapter to AdaptiveTableLayout.
Fragment/Activity usage
mTableLayout = (AdaptiveTableLayout) view.findViewById(R.id.tableLayout);
...
mTableAdapter = new SampleLinkedTableAdapter(getContext(), mCsvFileDataSource);
mTableAdapter.setOnItemClickListener(...);
mTableAdapter.setOnItemLongClickListener(...);
mTableLayout.setAdapter(mTableAdapter);
...
mTableLayout.setHeaderFixed(true);
mTableLayout.setSolidRowHeader(true);
mTableAdapter.notifyDataSetChanged();
XML usage
<com.cleveroad.adaptivetablelayout.AdaptiveTableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
app:cellMargin="1dp"
app:fixedHeaders="true"
app:solidRowHeaders="true" />