-
-
Android输入框控件ClearEditText实现清除功能
2020-09-02 09:19:34主要为大家详细介绍了Android输入框控件ClearEditText实现清除功能,感兴趣的小伙伴们可以参考一下 -
android输入框与文本框加滚动条scrollview示例
2020-09-04 11:13:06主要介绍了android输入框与文本框加滚动条scrollview示例,需要的朋友可以参考下 -
android输入框内容改变的监听事件实例
2020-08-27 23:39:22下面小编就为大家分享一篇android输入框内容改变的监听事件实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 -
Android-一个支持多种风格的密码(验证码)Android输入框
2019-08-12 18:15:06一个支持多种风格的密码(验证码)Android输入框 -
Android输入框添加emoje表情图标的实现代码
2020-09-01 06:09:55主要为大家详细介绍了Android输入框添加emoje表情图标的实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 -
Android输入框实时模糊搜索效果的示例代码
2020-08-18 16:21:41主要介绍了Android输入框实时模糊搜索效果的示例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 -
Android输入框实时模糊搜索
2020-08-04 10:45:34Android输入框实时模糊搜索 很多开发场景会用到搜索框实时模糊搜索来帮助用户输入内容,如图 思路是在EditText 字符变动的时候 弹出ListPopupwindow并更新列表,这样的做法google已经封装为AutoCompleteTextView ...Android输入框实时模糊搜索
很多开发场景会用到搜索框实时模糊搜索来帮助用户输入内容,如图
思路是在EditText 字符变动的时候 弹出ListPopupwindow并更新列表,这样的做法google已经封装为AutoCompleteTextView
用法
mAutoCompleteTextView.setAdapter(adapter); mAutoCompleteTextView.setFocusable(true); mAutoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
adapter自定义
Adapter 继承 BaseApdater 需要实现 Filterable 接口private class SearchAdapter extends BaseAdapter implements Filterable { private Context mContext; public SearchAdapter(Context context) { super(); this.mContext = context; } @Override public int getCount() { if (mSearchCustomEntities == null) { return 0; } else { return mSearchCustomEntities.size(); } } @Override public Object getItem(int position) { if (mSearchCustomEntities == null) { return null; } else { return mSearchCustomEntities.get(position); } } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(mContext).inflate(R.layout.item_search_custom, null, false); holder.tag = (TextView) convertView.findViewById(R.id.tv_custome_type); holder.name = (TextView) convertView.findViewById(R.id.custom_name); holder.phone = (TextView) convertView.findViewById(R.id.tv_phone); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.phone.setText(mSearchCustomEntities.get(position).phone); holder.name.setText(mSearchCustomEntities.get(position).name); if (mSearchCustomEntities.get(position).type == CustomerType.TEMPORARY_CUSTOMER.getType()) { holder.tag.setVisibility(View.VISIBLE); holder.tag.setText(mContext.getString(R.string.tag_temp)); holder.tag.setTextColor(mContext.getResources().getColor(R.color.customer_temp_txt)); holder.tag.setBackground(mContext.getResources().getDrawable(R.drawable.bg_solid_quote_type_inner_temp)); } else if (mSearchCustomEntities.get(position).type == CustomerType.COLLECTIVE_UNIT.getType()) { holder.tag.setVisibility(View.VISIBLE); holder.tag.setText(mContext.getString(R.string.tag_unit)); holder.tag.setTextColor(mContext.getResources().getColor(R.color.customer_unit_txt)); holder.tag.setBackground(mContext.getResources().getDrawable(R.drawable.bg_solid_quote_type_inner_unit)); } else if (mSearchCustomEntities.get(position).type == CustomerType.OUTER_MOTORCADE.getType()) { holder.tag.setVisibility(View.VISIBLE); holder.tag.setText(mContext.getString(R.string.tag_car)); holder.tag.setTextColor(mContext.getResources().getColor(R.color.customer_car_txt)); holder.tag.setBackground(mContext.getResources().getDrawable(R.drawable.bg_solid_quote_type_inner_car)); } else { holder.tag.setVisibility(View.GONE); } return convertView; } @Override public Filter getFilter() { if (mFilter == null) { mFilter = new ArrayFilter(); } return mFilter; } private class ViewHolder { TextView tag; TextView name; TextView phone; }
自定义 过滤器
private class ArrayFilter extends Filter { @Override protected FilterResults performFiltering(CharSequence prefix) { FilterResults results = new FilterResults(); String prefixString = prefix.toString(); //筛选部分 访问接口 XbcClient.getCustomList(prefixString, new EntitiesObserver<SearchCustomEntity>() { @Override protected void onGot(List<SearchCustomEntity> entities, String msg, int errCode) { if (entities != null && entities.size() > 0) { mSearchCustomEntities.clear(); mSearchCustomEntities.addAll(entities); mSearchAdapter.notifyDataSetChanged(); }else{ if (mSearchCustomEntities!=null & mSearchCustomEntities.size()>0) { mSearchCustomEntities.clear(); mSearchAdapter.notifyDataSetInvalidated(); } } } }); results.values = mSearchCustomEntities; results.count = mSearchCustomEntities.size(); return results; }
-
Android 输入框监听输入数字
2018-11-02 09:36:23Android 输入框监听 可以配置整数位、小数位、可输入最小值 package com.chainplus.idasex.utils; import android.text.Editable; import android.text.TextWatcher; import android.widget.EditText; import ...Android 输入框监听
可以配置整数位、小数位、可输入最小值
package com.chainplus.idasex.utils; import android.text.Editable; import android.text.TextWatcher; import android.widget.EditText; import com.chainplus.idasex.listener.TextWatchCallBack; /** * desc: 输入框数字输入监听,几位小数几位整数 * author: yangtao * <p> * creat: 2018/8/19 19:05 */ public class CountTextWatcher implements TextWatcher { EditText editText; TextWatchCallBack callBack; //整数位 private int INTEGER_COUNT = 5; //小数位 private int DECIMAL_COUNT = 2; private double MIN_MARK = 0.01; public CountTextWatcher(EditText editText, TextWatchCallBack callBack, int max1, int max2) { this.editText = editText; this.callBack = callBack; this.INTEGER_COUNT = max1; this.DECIMAL_COUNT = max2; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //设置最小值位MIN_MARK if (start > 2) { double num = Double.parseDouble(s.toString()); //此处可设置最小值 //if (num < MIN_MARK && s.toString().length() > 3) { // s = String.valueOf(MIN_MARK); // editText.setText(s); // } editText.setSelection(s.length()); } //首位连续2个0剔除为0. if (s.toString().equals("00") || s.toString().equals("01") || s.toString().equals("02") || s.toString().equals("03") || s.toString().equals("04") || s.toString().equals("05") || s.toString().equals("06") || s.toString().equals("06") || s.toString().equals("07") || s.toString().equals("08") || s.toString().equals("09")) { editText.setText("0."); editText.setSelection(2); } if (s.toString().length() > 1 && !s.toString().contains(".") && s.toString().startsWith("0")) { editText.setText(s.subSequence(1, s.length())); } } @Override public void afterTextChanged(Editable s) { judgeNumber(s, editText, INTEGER_COUNT, DECIMAL_COUNT); editText.setSelection(editText.getText().toString().length()); callBack.onSuccess(editText); } /** * 金额输入框中的内容限制(最大:小数点前五位,小数点后2位) * * @param edt */ public static void judgeNumber(Editable edt, EditText editText, int max1, int max2) { String temp = edt.toString(); int posDot = temp.indexOf(".");//返回指定字符在此字符串中第一次出现处的索引 int secondDot = temp.indexOf(".", posDot + 1); int index = editText.getSelectionStart();//获取光标位置 if (posDot == 0) {//必须先输入数字后才能输入小数点 edt.delete(0, temp.length());//删除所有字符 return; } if (posDot < 0) {//不包含小数点 if (temp.length() <= max1) { return;//小于五位数直接返回 } else { edt.delete(index - 1, index);//删除光标前的字符 return; } } if (posDot > max1) {//小数点前大于5位数就删除光标前一位 edt.delete(index - 1, index);//删除光标前的字符 return; } //为整数 //此时不能再次在外层设置setSelection属性 if (max2 == 0 && posDot > 0) { editText.setText(temp.substring(0, temp.length() - 1));//删除光标前的字符 return; } //重复小数点 if (secondDot != -1 && secondDot > posDot) {//小数点删除光标前一位小数点 edt.delete(index - 1, index);//删除光标前的字符 return; } if (temp.length() - posDot - 1 > max2 && index - 1 >= 0)//如果包含小数点 { edt.delete(index - 1, index);//删除光标前的字符 return; } } }
import android.widget.EditText; /** * desc: 输入完回调接口 * author: yangtao * <p> * creat: 2018/8/21 16:05 */ public interface TextWatchCallBack { void onSuccess(EditText editText); }
使用方式:
getEditext().addTextChangedListener(new CountTextWatcher(inputQuantity.getEditext(), new TextWatchCallBack() { @Override public void onSuccess(EditText editText) { } //整数位5位,小数位2位 }, 5, 2));
-
android 输入框EditText禁止输入Emoji表情符
2015-04-30 09:42:16android 输入框EditText禁止输入Emoji表情符,博客地址:http://blog.csdn.net/elsdnwn/article/details/45390771 -
android输入框内容改变的监听事件
2017-06-16 09:12:25android输入框内容改变的监听事件一般用于比如我们常见的:登录qq时 用户名输入完整时头像自动显示,或者注册用户时实时提示注册格式是否正确等。那么我们在这里举例:判断输入框是否有内容,来改变按钮的状态,常...android输入框内容改变的监听事件一般用于比如我们常见的:登录qq时 用户名输入完整时头像自动显示,或者注册用户时实时提示注册格式是否正确等。那么我们在这里举例:判断输入框是否有内容,来改变按钮的状态,常用于搜索一类。截图如下:(布局代码不再给出)
首先所在的activity要 implements TextWatcher并实现其方法:
familyPhonenum.addTextChangedListener(this);
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (!content.isEmpty()) { textView.setClickable(true); textView.setEnabled(true); textView.setTextColor(Color.BLUE); } else { textView.setClickable(false); textView.setEnabled(false); textView.setTextColor(Color.GRAY); } } @Override public void afterTextChanged(Editable s) { }
欢迎关注技术公众号,微信号搜索ColorfulCode 代码男人
分享技术文章,投稿分享,不限技术种类,不限技术深度,让更多人因为分享而受益。
-
Android 输入框限制字符输入数
2015-03-20 17:53:39Android输入框字符数量输入限制实现方式有时候对Android的输入框有字符输入数量的限制,并且显示字符输入的数量。通过以下方式可以实现:
1.自定义LimitNumEditText继承EditText
import android.content.Context; import android.content.res.TypedArray; import android.telephony.SmsMessage; import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; import android.util.AttributeSet; import android.widget.EditText; import us.pinguo.cc.R; /** * Created by crab on 15-3-18. */ public class LimitNumEditText extends EditText { private int mMaxLength; private OnTextCountChangeListener mTextCountChangeListener; public LimitNumEditText(Context context) { this(context, null); } public LimitNumEditText(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LimitNumEditText); mMaxLength = typedArray.getInt(R.styleable.LimitNumEditText_maxLength, -1); typedArray.recycle(); if (mMaxLength >= 0) { setFilters(new InputFilter[]{new InputFilter.LengthFilter(mMaxLength)}); } else { setFilters(new InputFilter[0]); } addTextChangedListener(null); } /** * @return 返回限制输入的最大字符数量 */ public int getLimitLength(){ return mMaxLength; } @Override public void addTextChangedListener(final TextWatcher watcher) { TextWatcher inner=new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if(watcher!=null){ watcher.beforeTextChanged(s,start,count,after); } } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { int[] params= SmsMessage.calculateLength(s,false); int use=params[1]; if(mMaxLength>=0 && mTextCountChangeListener!=null){ mTextCountChangeListener.onTextCountChange(use,mMaxLength); } if(watcher!=null){ watcher.onTextChanged(s,start,before,count); } } @Override public void afterTextChanged(Editable s) { if(watcher!=null){ watcher.afterTextChanged(s); } } }; super.addTextChangedListener(inner); } public LimitNumEditText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setOnTextCountChangeListener(OnTextCountChangeListener listener){ mTextCountChangeListener=listener; } /** * 监听输入框字符变化 */ public interface OnTextCountChangeListener{ /** * * @param use 输入字符赞据的大小 * @param total 限制输入数量的上线 */ public void onTextCountChange(int use, int total); }
2.修改res/values/attrs.xml文件,增加如下行
<declare-styleable name="LimitNumEditText">
<attr name="maxLength" format="integer" />
</declare-styleable>3.在布局文件中使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:algnText="http://schemas.android.com/apk/res-auto" android:background="#FFFFFF" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.example.crab.mycameratest.LimitNumEditText algnText:maxLength="20" android:id="@+id/id_edit_text_test" android:layout_width="match_parent" android:layout_height="50dp"/> </LinearLayout>
-
android输入框取消横屏全屏输入
2017-09-05 11:17:12android输入框在横评的时候如果不做特殊处理,点击输入框的时候会弹出新的界面来输入,如果我们需要设置在惦记的时候还能看到输入框,就需要在布局中加入相应的属性。 android:imeOptions=”flagNoExtractUi”。... -
android 输入框 EditTextView
2019-06-28 10:29:29有的公司后台提交数据没有支持android的表情符号,导致提交一些表单数据中带有系统的表情时,接口会返回500错误。 果: 针对这种情况,可在每次输入完一个值后监听最后一位是不是表情,如果是表情,就删除掉。 注... -
android输入框 digst与键盘模式的冲突解决
2019-03-29 15:58:03android输入框 digst与键盘模式的冲突解决 现需求对输入框的可输入文字进行控制 如 <string name="letter1">0123456789.</string> <string name="letter2">0123456789... -
Android输入框限制两位小数(多位小数)
2020-04-13 10:55:29Android输入框限制两位小数,先来看看效果图 直接上代码,没有太多的神奇就是监听了输入框EditText的输入监听事件而已 picET.addTextChangedListener(new TextWatcher() { @Override public void ... -
安卓beforetextchanged_android输入框内容改变的监听事件实例
2021-01-17 17:21:42android输入框内容改变的监听事件一般用于比如我们常见的:登录qq时 用户名输入完整时头像自动显示,或者注册用户时实时提示注册格式是否正确等。那么我们在这里举例:判断输入框是否有内容,来改变按钮的状态,常... -
android 输入框自动匹配-AutoCompleteTextView
2013-04-17 16:46:33android 输入框自动匹配-AutoCompleteTextView 封装自动适配的adapter可以监听,并且可以监听自动匹配输入框的输入事件。 package com; import java.util.List; import android.app.Activity; import android.... -
Android 输入框样式UI
2018-10-26 17:55:34Android 好用的框架与UI效果demo收集 1.防京东,支付宝密码键盘和密码输入框https://github.com/GitPhoenix/Keyboard 2.验证码输入框控件.https://github.com/JustKiddingBaby/VercodeEditText Edittext 的... -
android输入框EditText详解
2017-07-19 15:54:511、设置输入框的默认值和默认值的字体颜色以及输入文件颜色 android:layout_height="wrap_content" android:layout_width="fill_parent" android:hint="用户名" android:textColor="#ADFF2F" android:... -
Android输入框下拉列表
2018-06-01 15:50:17今天物色了Android基础:两个特殊的输入框——炒鸡有意思的是,一直认为这两兄弟跟TextView亲,事实是他们更类似于EditText。1.AutoCompleteTextView2.MultiAutoCompleteTextView... -
Android输入框自动提示
2018-10-26 15:22:28Android用的有两种方法AutoCompleteTextView和MultiAutoCompleteTextView,第二种可以连续提示输入,如下图 AutoCompleteTextView常用属性 android:completionHint 设置出现在下拉菜单中的提示标题...
收藏数
6,445
精华内容
2,578