在我的列表视图中有四个文本视图和图像。在ArrayAdapter中实现getFilter()android listview
我想设置过滤器上txtcompany文本视图
我想实现一个用getFilter(),但它提供了一个错误的结果
请帮助我如何能在列表视图
实现用getFilter()列表视图ArrayAdapter源代码
类数据延伸ArrayAdapter {
Button imageView;
TextView txtcompany;
TextView txtDesc;
TextView txtPosition;
TextView txtState;
TextView txtCity;
String[] companyarray;
String[] positonarray;
String[] cityarray;
String[] statearray;
String[] Descarray;
String[] contry;
String[] pass;
ArrayList<String> receiceValueOfAdapter=new ArrayList<String>(6);
ArrayList<String> time=new ArrayList<String>(6);
Context context;
Data(Context c, String[] company, String[] position, String[] city, String[] state,ArrayList<String> receiveValue, String[] Desc,ArrayList<String> time1,
String[] pass,String[] contry)
{
super(c,R.layout.list_item,R.id.txt_company,company);
this.context=c;
this.pass=pass;
this.companyarray=company;
this.positonarray=position;
this.cityarray=city;
this.statearray=state;
this.receiceValueOfAdapter=receiveValue;
this.Descarray=Desc;
this.time=time1;
this.contry=contry;
}
public View getView(int position, View convertView, ViewGroup parent) {
final String description;
String upperString="";
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View row;
row=mInflater.inflate(R.layout.list_item, parent,false);
txtcompany = (TextView) row.findViewById(R.id.txt_company);
imageView = (Button) row.findViewById(R.id.img);
//imageView.setVisibility(View.INVISIBLE);
txtPosition= (TextView) row.findViewById(R.id.txt_position);
txtCity= (TextView) row.findViewById(R.id.txt_city);
txtState= (TextView) row.findViewById(R.id.txt_state);
if(companyarray[position].toString().length()>0)
upperString = companyarray[position].substring(0,1).toUpperCase() + companyarray[position].substring(1);
txtcompany.setText(" "+upperString);
txtPosition.setText(" "+positonarray[position]);
Log.d("City",statearray[position]+"City "+cityarray[position]);
if(cityarray[position].toString().length()==0)
{
txtCity.setText(statearray[position]);
}
if(statearray[position].toString().trim().length()==0)
{
txtCity.setText(" "+cityarray[position]);
}
if(statearray[position].toString().trim().length()<2 && cityarray[position].toString().trim().length()<2)
{
txtCity.setText(" "+contry[position]);
}
if(statearray[position].toString().trim().length()>=2 && cityarray[position].toString().trim().length()>=2)
{
txtCity.setText(" "+cityarray[position]+", "+statearray[position]);
}
txtState.setText(""+time.get(position));
imageView.setTag(receiceValueOfAdapter.get(position));
description= Descarray[position];
final int l=position;
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
// Toast.makeText(contect, ""+ txtPosition.getText().toString(), Toast.LENGTH_LONG).show();
try{
String strurl1=pass[l].trim();
String strurl= strurl1.trim();
if (!strurl.trim().startsWith("https://") && !strurl.trim().startsWith("http://")){
strurl = "http://"+ strurl;
}
Intent ii = new Intent(Intent.ACTION_VIEW);
ii.setData(null);
ii.setData(Uri.parse(strurl));
startActivity(ii);
}
catch(Exception e)
{
}
}
});
return row;
}
}
的EditText变化监听器java代码
lstsearch.addTextChangedListener(new TextWatcher()
{
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
{
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
{
Main_listview.this.datadap.getFilter().filter(charSequence);
}
public void afterTextChanged(Editable editable)
{
}
});
检查此链接http://www.androidbegin.com/tutorial/android-search-filter-listview-images-and-texts-tutorial/ – rajahsekar 2014-10-06 10:42:12
必须使用柯森适配器和比它 – 2014-10-06 10:49:13
APPY过滤器如何使用curson适配器 – 2014-10-06 11:40:25