有沒有一種方法可以通過自定義類中的列表進行搜索?如果可能,我還想添加語音搜索。Android:通過自定義列表搜索
聲音類
private int _id;
private String _productname;
private String _extra;
private int _image;
public SoundListed() {
}
public SoundListed(int id, String productname, String extra, int image) {
this._id = id;
this._productname = productname;
this._extra = extra;
this._image=image;
}
public SoundListed(String productname, String extra, int image) {
this._productname = productname;
this._extra = extra;
this._image=image;
}
public void setID(int id) {
this._id = id;
}
public int getID() {
return this._id;
}
public int getImage(){return this._image;}
public void setProductName(String productname) {
this._productname = productname;
}
public String getProductName() {
return this._productname;
}
public void setExtra(String extra) {
this._extra = extra;
}
public String getExtra() {
return this._extra;
}
And the adapter:
public class soundAdapter extends ArrayAdapter{
private Context context;
private List <SoundListed> listSounds;
public soundAdapter(Context context, List<SoundListed> friends) {
super(context, R.layout.customrow, friends);
this.context=context;
this.listSounds=friends;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=inflater.inflate(R.layout.soundrow,null);
}
SoundListed s = listSounds.get(position);
TextView soundName = (TextView)convertView.findViewById(R.id.nameOfFile);
TextView soundExtras = (TextView)convertView.findViewById(R.id.extraText);
soundName.setText(s.getProductName());
soundExtras.setText(s.getExtra());
return convertView;
}
}
簡短的解釋 - 這有點響板的,我婉用戶能夠與soundExtras和soundName(我使用的操作欄搜索插件可以同時搜索通過列表搜索)
在此先感謝!
首先過濾列表類基於搜索的文本,並將其發送到適配器上的文字更改,重新使用新值列表 –
如何?你可以給我一個例子 – EnderNicky
@EnderNicky我更新了我的答案 – arun