我似乎无法找到如何使我的自定义#!/usr/bin/env ruby
string = "<li>Physical education sed<span class=\"meta\"><ul><li>15184745922</li></ul></span></li>"
one, two = string.match(/<li>(.*?)<.*?<li>(.*?)</i).captures
p one #=> "Physical education sed"
p two #=> "15184745922"
工作。
我的getFilter()
扩展了CustomAdapter
,因为我已经知道它没有实现过滤,所以我需要自己做。我以各种方式尝试过,但没有成功。
问题1:工作方法是什么? (如何正确实现过滤?)
Q2:如何更改BaseAdapter
(!)以便过滤是一种自动功能?
请,不要忽视! 非常感谢提前!
这是一段代码:
Main.java
CustomAdapter
CustomAdapter.java
// import ....
public class MainActivity extends Activity {
ListView lv;
Context context;
EditText et;
CustomAdapter adapter;
View v;
public int [] Images= {R.drawable.1,R.drawable.2,R.drawable.3,R.drawable.4};
public String [] NameList={"item1","item2","item3","item4"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context=this;
lv=(ListView) findViewById(R.id.listView);
adapter = new CustomAdapter(this, fruitNameList,fruitImages);
lv.setAdapter(adapter);
et = (EditText)findViewById(R.id.editText);
/**
* Enabling Search Filter
* */
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
MainActivity.this.adapter.getFilter().filter(cs); // !!!!getFilter() is not found I tried to write methods on my own but nothing worked
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}// end of onCreate
public void onClick (View v) {
switch (v.getId()) {
case R.id.search:
et.setVisibility(v.VISIBLE);
et.setHint("Search names...");
break;
}
}
public void SearchFilterEnable() {
/**
* Enabling Search Filter
* */
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
MainActivity.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
}