Android中的小技巧
来源:互联网 发布:郑州青峰网络 编辑:程序博客网 时间:2024/06/16 21:17
- Android中
ListView
等滚动到某个位置失效
//第一种lv.setSelection(position)//第二种lv.smoothScrollToPosition(position)
第一种直接就是选中位置,第二种有滚动动画,但是有时候,滚动效果看不到,解决方式新建一个runnable,如下:
lv.post(new Runnable() { @Override public void run() { lv.smoothScrollToPosition(position); } });
- 类似的问题,就是使用
SwipeRefreshLayout
的时候,希望打开页面的时候,SwipeRefreshLayout
正在刷新,可是调用SwipeRefreshLayout的setRefreshing(true)
无效,主要原因是页面未渲染完成,解决方式就是延迟执行刷新。
srl.post(new Runnable() { @Override public void run() { srl.setRefreshing(true); } });
EditText
限制输入的小数位数
Android中提供了一个输入过滤器InputFilter
,用于过滤用户输入的内容。- 定义一个类实现
InputFilter
接口
- 定义一个类实现
public class DoubleInputFilter implements InputFilter { /** * 输入框小数的位数 示例保留一位小数 */ private static final int DECIMAL_DIGITS = 2; /** * This method is called when the buffer is going to replace the * range <code>dstart … dend</code> of <code>dest</code> * with the new text from the range <code>start … end</code> * of <code>source</code>. Return the CharSequence that you would * like to have placed there instead, including an empty string * if appropriate, or <code>null</code> to accept the original * replacement. Be careful to not to reject 0-length replacements, * as this is what happens when you delete text. Also beware that * you should not attempt to make any changes to <code>dest</code> * from this method; you may only examine it for context. * <p> * Note: If <var>source</var> is an instance of {@link Spanned} or * {@link Spannable}, the span objects in the <var>source</var> should be * copied into the filtered result (i.e. the non-null return value). * {@link TextUtils#copySpansFrom} can be used for convenience. * * @param source * @param start * @param end * @param dest * @param dstart * @param dend */ @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if ("".equals(source.toString())) { return null; } String value = dest.toString(); String[] split = value.split("\\."); if (split.length > 1) { String s = split[1]; int i = s.length() + 1 - DECIMAL_DIGITS; if (i > 0) { return source.subSequence(start, end - i); } } return null; }}
- 使用
et.setFilters(new InputFilter[]{new DoubleInputFilter()});
阅读全文
0 0
- android中的小技巧
- android中的小技巧
- Android中的小技巧
- Android中的小技巧
- android开发中的小技巧
- android中的一些小技巧
- Android开发中的小技巧
- Android开发中的小技巧
- Android开发中的小技巧
- Android开发中的小技巧
- android中的小布局技巧
- 几点Android 开发中的小技巧
- Android 开发中的一些小技巧
- android 调试中的一些小技巧
- Android 开发中的一些小技巧
- Android 开发中的一些小技巧
- Android studio中的一些小技巧
- Android开发中的小技巧(1)
- 1010. 一元多项式求导 (25)
- Python-面向对象编程
- Android 高级混淆和代码保护技术
- Makefile经典教程(掌握这些足够)
- sqlserver/oracle当插入表数据时同时修改其中一个字段的触发器
- Android中的小技巧
- Tracking-Learning-Detection (TLD算法总结)
- React 编程思想 正反向数据流(单向数据流) 为了好理解我才叫正反向
- Spring MVC3.0.5搭建全程
- Android Blogs
- 对象中的数组-《数据结构与算法》
- 概率统计领域大牛主页网址
- MAC下使用eclipse进行svn相关配置
- js页面之间以及vue $http请求向后台传递参数中文乱码问题解决