• 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 dstart … dend of dest     * with the new text from the range start … end     * of source.  Return the CharSequence that you would     * like to have placed there instead, including an empty string     * if appropriate, or null 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 dest     * from this method; you may only examine it for context.     * 

* Note: If source is an instance of {@link Spanned} or * {@link Spannable}, the span objects in the source 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()});

更多相关文章

  1. Android用户界面 UI组件--自动提示输入框 AutoCompleteTextView
  2. Android(安卓)Listview 隐藏滚动条
  3. Android输入法之输入系统
  4. Android输入法之——如何禁止横屏时全屏http://blog.csdn.net/na
  5. Android(安卓)SDK 中常用的几个命令
  6. Android(安卓)mac 真机调试
  7. Android(安卓)热修复使用Gradle Plugin1.5改造Nuwa插件
  8. Android控件TextView中ellipsize属性(设置当文字长度超过textview
  9. android在使用RecyclerView布局里的androidstudio的模拟器虚拟键

随机推荐

  1. Android(安卓)之 Binder与进程间通信
  2. Android系统升级那些事儿
  3. Android应用签名
  4. Android开发环境配置简介
  5. Android共享全局数据
  6. Android(安卓)call setting 源码分析 从
  7. Android——用户登陆及用户名和密码的保
  8. android
  9. Android遇上打印机
  10. Android(安卓)开发技术周报 Issue#287