位置: 编程技术 - 正文
推荐整理分享Android关键字模糊查询,并带有高亮效果(安卓关键词覆盖),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:android关键字大全,android关键字高亮,android volatile关键字的作用,android文字按钮,手机关键字,手机关键字,android关键字高亮,android关键字高亮,内容如对您有帮助,希望把文章链接给更多的朋友!
主要功能代码在aftertextchange方法中操作,之前用
SpannableStringBuilder方法会出现错误,不能被序列化,所以只好用html拼接的方法
private TextWatchermTWatcher =new TextWatcher(){
@Override
public void onTextChanged(CharSequence s,int start, int before,int count) {
}
@Override
publicvoid beforeTextChanged(CharSequence s,int start,int count,
int after){
}
@Override
publicvoid afterTextChanged(Editable s){
int index;
if(editText.getText().toString().length()> 0){
clearBtn.setVisibility(View.VISIBLE);
wordEdt= editText.getText().toString().trim();
banks.clear();
for(int i= 0;i< branchList.size();i){
BankBranch bankBranch= branchList.get(i);
bankBranch.setSearchName(null);
String bankName= bankBranch.getName();
// ForegroundColorSpan span = new ForegroundColorSpan(getResources().getColor(R.color.red));//要显示的颜色
// SpannableStringBuilder builder = new SpannableStringBuilder(bankBranch.getName());
index= bankName.indexOf(wordEdt);//从第几个匹配上
if(index!= -1){
// builder.setSpan(span, index, indexwordEdt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
bankBranch.setSearchName(bankName.substring(0,index)getBankName(wordEdt)bankName.substring(indexwordEdt.length(), bankName.length()));
banks.add(bankBranch);
}
}
if(adapter==null){
adapter= newBranchAdapter(banks);
listV.setAdapter(adapter);
}else{
adapter.notifyDataSetChanged();
}
}else{
banks.clear();
clearBtn.setVisibility(View.INVISIBLE);
for(int i = 0; i < branchList.size(); i){
branchList.get(i).setSearchName(null);
banks.add(branchList.get(i));
}
adapter.notifyDataSetChanged();
}
}
};
private classBranchAdapter extendsBaseAdapter{
private ArrayList<BankBranch> list;
public BranchAdapter (ArrayList<BankBranch> list){
this.list=list;
}
@Override
publicint getCount(){
returnlist.size();
}
@Override
public Object getItem(int position){
returnlist.get(position);
}
@Override
public long getItemId(int position){
return position;
}
@SuppressLint("InflateParams")
@Override
public View getView(int position,View convertView, ViewGroup parent) {
ViewHolder holder= null;
if (convertView == null){
holder = new ViewHolder();
convertView= LayoutInflater.from(BankBranchActivity.this).inflate(
R.layout.simple_list_item,null);
holder.textV= (TextView) convertView.findViewById(R.id.item_text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
BankBranch branch= list.get(position);
if(branch.getSearchName()!= null){
holder.textV.setText(Html.fromHtml(branch.getSearchName()));
}else{
holder.textV.setText(branch.getName());
}
return convertView;
}
privateclass ViewHolder{
TextViewtextV;
}
}
颜色设置的方法
/**
* name1
* @return
*/
publicString getBankName(String name1){
String s1="<font color="#">"name1"</font>";
return s1;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
startActivity时报错Calling startActivity() from outside of an Activity conte 原因:Context中有一个startActivity方法,Activity继承自Context,重载了startActivity方法。如果使用Activity的startActivity方法,不会有任何限制,而如果使用Context
Activity生命周期讲解 前言:一直想着写一些Android基础知识分享给大家,但是有时候又觉得怕写不好误导了大家学习Android,思前想后觉得还是去Android官网看看,发现在Android
Android数据库高手秘籍:SQLite命令 要想熟练地操作任何一个数据库,最最基本的要求就是要懂SQL语言,这也是每个程序员都应该掌握的技能。虽说SQL博大精深,要想精通确实很难,但最
标签: 安卓关键词覆盖
本文链接地址:https://www.jiuchutong.com/biancheng/378102.html 转载请保留说明!上一篇:每一位Android开发者应该知道的Android体系架构和开发库(安卓开发者有多少)
下一篇:startActivity时报错Calling startActivity() from outside of an Activity conte(startactivity())
友情链接: 武汉网站建设