邮箱联想

news/2024/12/23 6:59:08/

布局
<LinearLayoutandroid:orientation="vertical"android:layout_marginTop="50dp"android:layout_width="match_parent"android:layout_height="wrap_content"><AutoCompleteTextViewandroid:id="@+id/autoComplete"android:layout_width="match_parent"android:layout_height="66dp" /><test.com.mp3.MailBoxAssociateViewandroid:id="@+id/imageviewedittextone"android:layout_width="match_parent"android:layout_height="58dp"android:layout_marginBottom="8dp"android:layout_marginStart="8dp"android:layout_marginTop="8dp"android:hint="地址"android:paddingLeft="5dp"android:popupBackground="@android:color/darker_gray"android:singleLine="true"android:textColor="@android:color/black"android:textColorHint="@android:color/holo_blue_bright"android:textSize="16sp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="@+id/autoComplete" /></LinearLayout>

 自定义 MailBoxAssociateView

package test.com.mp3;import android.content.Context;
import android.util.AttributeSet;/*** Created by T_baby on 17/12/25.* @后进行提示*/public class MailBoxAssociateView extends android.support.v7.widget.AppCompatMultiAutoCompleteTextView {public MailBoxAssociateView(Context context) {super(context);}public MailBoxAssociateView(Context context, AttributeSet attrs) {super(context, attrs);}public MailBoxAssociateView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}@Overridepublic boolean enoughToFilter() {// 如果字符中包含'@'并且不在第一位,则满足条件return getText().toString().contains("@") && getText().toString().indexOf("@") > 0;}
}

类 MailBoxAssociate tokenizer

package test.com.mp3;import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.widget.MultiAutoCompleteTextView;/*** Created by T_baby on 17/12/25.*/public class MailBoxAssociateTokenizer implements MultiAutoCompleteTextView.Tokenizer {@Overridepublic int findTokenEnd(CharSequence text, int cursor) {int i = cursor;int len = text.length();while (i < len) {if (text.charAt(i) == '@') {return i;} else {i++;}}return len;}@Overridepublic int findTokenStart(CharSequence text, int cursor) {int index = text.toString().indexOf("@");if (index < 0) {index = text.length();}if (index >= findTokenEnd(text, cursor)) {index = 0;}return index;}@Overridepublic CharSequence terminateToken(CharSequence text) {int i = text.length();while (i > 0 && text.charAt(i - 1) == ' ') {i--;}if (i > 0 && text.charAt(i - 1) == '@') {return text;} else {if (text instanceof Spanned) {SpannableString sp = new SpannableString(text);TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);return sp;} else {return text;}}}}

类 Autocompale

package test.com.mp3;import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;import java.util.ArrayList;
import java.util.List;/*** Created by T_baby on 17/12/25.* 自动提示*/public class AutoComplete extends AutoCompleteTextView {//输入字符进行联想,@163.com、@126.com、@qq.com、@sina.com、@yeah.net、@yahoo.com、@gmail.com等常用邮箱private static final String[] emailSuffix = {"@qq.com", "@163.com", "@126.com", "@gmail.com", "@sina.com", "@hotmail.com","@yahoo.cn", "@sohu.com", "@foxmail.com", "@139.com", "@yeah.net", "@vip.qq.com", "@vip.sina.com"};public AutoComplete(Context context) {super(context);init(context);}public AutoComplete(Context context, AttributeSet attrs) {super(context, attrs);init(context);}private void init(Context context) {final MyAdatper adapter = new MyAdatper(context);setAdapter(adapter);addTextChangedListener(new TextWatcher() {@Overridepublic void afterTextChanged(Editable s) {String input = s.toString();adapter.mList.clear();if (input.length() > 0) {for (int i = 0; i < emailSuffix.length; ++i) {adapter.mList.add(input + emailSuffix[i]);}}adapter.notifyDataSetChanged();showDropDown();}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int before,int count) {}});// default=2 当输入一个字符的时候就开始检测setThreshold(1);}class MyAdatper extends BaseAdapter implements Filterable {List<String> mList;private Context mContext;private MyFilter mFilter;public MyAdatper(Context context) {mContext = context;mList = new ArrayList<String>();}@Overridepublic int getCount() {return mList == null ? 0 : mList.size();}@Overridepublic Object getItem(int position) {return mList == null ? null : mList.get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {if (convertView == null) {TextView tv = new TextView(mContext);tv.setTextColor(Color.BLACK);tv.setTextSize(20);convertView = tv;}TextView txt = (TextView) convertView;txt.setText(mList.get(position));return txt;}@Overridepublic Filter getFilter() {if (mFilter == null) {mFilter = new MyFilter();}return mFilter;}private class MyFilter extends Filter {@Overrideprotected FilterResults performFiltering(CharSequence constraint) {FilterResults results = new FilterResults();if (mList == null) {mList = new ArrayList<String>();}results.values = mList;results.count = mList.size();return results;}@Overrideprotected void publishResults(CharSequence constraint, FilterResults results) {if (results.count > 0) {notifyDataSetChanged();} else {notifyDataSetInvalidated();}}}}
}

MainActivity

MailBoxAssociateView view;
private String[] email_sufixs = new String[]{"@qq.com", "@163.com", "@126.com", "@gmail.com", "@sina.com", "@hotmail.com","@yahoo.cn", "@sohu.com", "@foxmail.com", "@139.com", "@yeah.net", "@vip.qq.com", "@vip.sina.com"};

在onCreateview中

view = findViewById(R.id.imageviewedittextone); MailBoxAssociateTokenizer mailBoxAssociateTokenizer = new MailBoxAssociateTokenizer(); ArrayAdapter<String> adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, email_sufixs); view.setAdapter(adapter); view.setTokenizer(mailBoxAssociateTokenizer);

 

http://www.ppmy.cn/news/125355.html

相关文章

2022款联想拯救者Y9000P和Y9000X的区别

在硬件配置方面&#xff0c;联想拯救者这两款游戏本的主要区别是在显卡的功耗&#xff0c;内存扩展性方面不一样&#xff0c;其中联想拯救者Y9000P 2022款的rtx3060显卡功耗是140w&#xff0c;而Y9000X的rtx3060功耗是100w。Y9000P的内存是支持双内存和双硬盘扩展&#xff0c;而…

联想ThinkPad安装windows7系统详细图文教程

uefi启动作为一种新的引导启动模式&#xff0c;使用uefi启动的笔记本&#xff0c;台式电脑&#xff0c;如果想用u盘启动就必须将u盘制作成支持uefi启动的模式&#xff0c;下面一起来看看u深度制作uefi启动u盘的详细方法。 文章目录 准备工作一、uefi启动u盘详细制作方法1.下载工…

P176-P370

1.Person p2p1&#xff1b; 将p1变量保存的对象地址值赋给p2&#xff0c;导致p1和p2指向了堆空间中的同一个对象实体 2.属性&#xff1a;直接声明在一对{}内&#xff0c;可以在声明属性时&#xff0c;指明其权限&#xff0c;使用权限修饰符。 局部变量&#xff1a;声明在方法内…

联想拯救者相关驱动问题修复及升级

电脑由于重装系统后双显示屏无法正常工作&#xff0c;经排查是原先驱动不适配&#xff0c;需要更新驱动&#xff0c;这里有两个快速便捷的方法想记录一下&#xff1a; 第一个方法&#xff08;最简单&#xff0c;推荐&#xff09;&#xff0c;即登录联想官方网站&#xff1a; …

联想(Lenovo)小新锐7000 一系列问题

昨日删除了一些明显不是系统软件的东西&#xff0c;想清理一下无用软件&#xff0c; 删完之后无法进入windows了。。。。费了好大功夫才把资料都拷出来&#xff0c; 然后又重装了一下系统&#xff1a; 总结如下&#xff1a; 1.卸载相关软件&#xff08;比如数据恢复或者一键激…

艾美捷抗人IL-12 (p70)单抗MT704相关参数说明

艾美捷抗人IL-12 (p70)单抗MT704相关参数&#xff1a; 英文名称&#xff1a;Anti-human IL-12 (p70) mAb (MT704), biotin 编号&#xff1a;3455-6-1000 应用&#xff1a;酶联免疫吸附试验/酶标仪 反应性&#xff1a;人类 / NHP 格式&#xff1a;生物素化 同种型&#xf…

联想拯救者R720安装Win7系统

客户入手的联想拯救者R720笔记本电脑&#xff0c;需要改成Windows7 64位旗舰版系统&#xff0c;今天就安装了一下&#xff0c;啊哈! 京东上这一款 标题&#xff1a;联想&#xff08;Lenovo&#xff09; 拯救者R720 15.6英寸游戏笔记本电脑 i7-7700HQ GTX1050Ti 4G 32G 512G1T升…

ThinkPad P73 拆机清灰日志

P73 用了快2年&#xff0c;说实在的&#xff0c;没有感觉功能很强大&#xff0c;至少跑大型3D游戏比如地平线、Anno 1800 GPU温度90&#xff0c;风扇呼啸。 按理说最高配RTX P5000, E2276,128G内存&#xff0c;不至于这样。 都说Thinkpad的硅脂是牙膏厂配的&#xff0c;然后看…