TagView引用笔记
来源:互联网 发布:java web发布到服务器 编辑:程序博客网 时间:2024/06/14 15:22
#build.gradle
In your project root path build.gradle file, add this:
allprojects { repositories { ... maven { url "https://jitpack.io" } }}
And in your module path build.gradle file, add this:
dependencies { compile 'com.github.onlynight:TagLayout:1.2.0'}
#Sample Code
xml layout file:
<com.github.onlynight.taglayout.library.TagLayout android:id="@+id/tagLayout" android:layout_width="match_parent" android:layout_height="wrap_content" app:maxSelectCount="none"/>
java controller file:
private TagLayout tagLayout;private TagAdapter adapter;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tagLayout = (TagLayout) findViewById(R.id.tagLayout); initAdapter(); setSelectMode(); setSelect(); setListener();}private void initAdapter() { List<Tag> data = new ArrayList<>(); for (int i = 0; i < 20; i++) { data.add(new Tag(getResources().getString(R.string.tag) + (i + 1))); } adapter = new TagAdapter(this); adapter.addTags(data); tagLayout.setAdapter(adapter);}private void setSelectMode() { tagLayout.setSelectMode(TagLayout.SELECT_MODE_SINGLE); // this method is the same as setSelectMode(); // tagLayout.setMaxSelectCount(1);}private void setSelect() { List<Integer> selected = new LinkedList<>(); for (int i = 0; i < 6; i++) { selected.add(14 + i); } tagLayout.setSelect(selected);}private void setListener() { tagLayout.setOnTagItemSelectedListener(new TagLayout.OnTagItemSelectedListener() { @Override public void onSelected(boolean selected, int currentSelected, List<Integer> allSelected) { String showStr = ""; if (selected) { showStr = "select item " + currentSelected; } else { showStr = "cancel select item " + currentSelected; } Toast.makeText(MainActivity.this, showStr, Toast.LENGTH_SHORT).show(); } @Override public void onCanNotSelectMore(boolean selected, int currentSelected, List<Integer> allSelected) { Toast.makeText(MainActivity.this, "the MAX select item is " + tagLayout.getMaxSelectCount(), Toast.LENGTH_SHORT).show(); } });}
You need a adapter extends BaseAdapter just like ListView’s Adapter.
#XML property explain
<declare-styleable name="TagLayout"> <!-- set the max select count; the default value is 1, it means you can select one item at the same time.--> <attr name="maxSelectCount" format="integer|enum"> <enum name="all" value="-1"/> <enum name="single" value="1"/> <enum name="none" value="0"/> </attr> <!-- is the all item in one line, the default value is false --> <attr name="singleLine" format="boolean"/> <!-- set the max item in one line the default is -1, that means view will auto calculate the child in one line.--> <attr name="maxItemsInOneLine" format="integer"/> <!-- if the item has equal width, the default is false. this property only when you set maxItemsInOneLine property, then this will effect--> <attr name="isItemsEqualWidth" format="boolean"/></declare-styleable>
#API explain
/** * To set this listener you can listen item select action and * listen there're no more tag can be selected * * @param onTagItemSelectedListener */public void setOnTagItemSelectedListener(OnTagItemSelectedListener onTagItemSelectedListener);/** * get the max select count * * @return */public int getMaxSelectCount();/** * set the base adapter * * @param adapter */public void setAdapter(BaseAdapter adapter);/** * clear all the selected item. */public void clearSelect();/** * get selected item id. * * @return a list of selected item's id. */public List<Integer> getSelected();/** * set item state to selected. * * @param items the items you want to be set select. */public void setSelect(List<Integer> items);/** * set the select mode. * * @param selectModeOrMaxSelectCount {@link TagLayout.SELECT_MODE_ALL} can select all.</p> * {@link TagLayout.SELECT_MODE_NONE} can select none.</p> * {@link TagLayout.SELECT_MODE_SINGLE} can select one.</p> * or you can set the max select count you want.</p> */public void setSelectMode(int selectModeOrMaxSelectCount);/** * set the tag layout max select count.</p> * this method is the same as {@link TagLayout#setSelectMode(int)} * * @param maxSelectCount it is bigger than 0,</p> * the -1 is means you can select all tag item.</p> * {@link TagLayout.SELECT_MODE_ALL} can select all.</p> * {@link TagLayout.SELECT_MODE_NONE} can select none.</p> * {@link TagLayout.SELECT_MODE_SINGLE} can select one.</p> */public void setMaxSelectCount(int maxSelectCount);
原文地址https://github.com/onlynight/TagLayout
阅读全文
0 0
- TagView引用笔记
- Android笔记(23)TagView标签
- TagView的用法及源码解析
- c++学习笔记--引用&
- “引用”学习笔记
- COM笔记-引用计数
- COM笔记-引用计数
- c++引用《笔记》
- COM笔记-引用计数
- COM笔记-引用计数
- JavaScript引用类型(笔记)
- c++引用学习笔记
- COM笔记-引用计数
- 《学习bash》笔记--引用
- java传引用笔记
- 引用和指针笔记
- C++引用 笔记
- Cpp引用Reference-笔记
- iOS模式分析-使用适配器模式重构TableView
- 设计模式简介
- test
- iOS使用UITableView实现的富文本编辑器
- SRS-DOLPHIN
- TagView引用笔记
- iOS使用Instrument-Time Profiler工具分析和优化性能问题
- Java is-a、has-a和like-a、组合、聚合和继承 两组概念的区别
- [Python]网络爬虫(三):使用cookiejar管理cookie 以及 模拟登录知乎
- 【iOS开发】自动识别剪贴板内容
- web服务器与web客户端通讯过程
- 缺少类型说明符
- POI excel操作备忘
- 阿丹学理财之储蓄