這個也是我自己通過網(wǎng)上找資料,自己寫的一個Demos。
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設、高性價比太倉網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式太倉網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設找我們,業(yè)務覆蓋太倉地區(qū)。費用合理售后完善,十年實體公司更值得信賴。內容簡單,直接代碼獻上;
public class MainActivity extends Activity {
List
EditText editinput;
ListView listview;
Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editinput = (EditText)findViewById(R.id.edit);
listview = (ListView)findViewById(R.id.ydlist);
initdata();
adapter = new Adapter( people);
listview.setAdapter(adapter);
editinput.addTextChangedListener(new watcher());
}
void initdata(){
people.add(new People("張三","1374456"));
people.add(new People("張三小子", "12444455"));
people.add(new People("李一", "1345555"));
people.add(new People("王一", "1355555"));
people.add(new People("王二", "1365555"));
people.add(new People("李三", "13565555"));
people.add(new People("李一", "123555"));
}
class watcher implements TextWatcher{
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String aa = s.toString();
Pattern p = Pattern.compile(aa);
List
for(int i=0;i People pp = people.get(i); Matcher matcher = p.matcher(pp.getName()+pp.getPhome()); if(matcher.find()){ we.add(pp); } } adapter = new Adapter( we); listview.setAdapter(adapter); } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } } public class Adapter extends BaseAdapter { private List Adapter(List // TODO Auto-generated constructor stub this.people = people; } @Override public int getCount() { // TODO Auto-generated method stub return people.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return people.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub People p = people.get(position); if(convertView==null){ convertView = getLayoutInflater().inflate(R.layout.yd_item, null); } TextView tv1 = (TextView) convertView.findViewById(R.id.ydtext1); TextView tv2 = (TextView) convertView.findViewById(R.id.ydtext2); tv1.setText(p.getName()); tv2.setText(p.getPhome()); return convertView; } } public class People { private String Name ; private String Phome; public String getName() { return Name; } public void setName(String name) { Name = name; } public String getPhome() { return Phome; } public void setPhome(String phome) { Phome = phome; } public People(String name,String phone){ super(); this.Name = name; this.Phome = phone; } } } xml的代碼: xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > android:id="@+id/edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="82dp" android:ems="10" > android:id="@+id/ydlist" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_below="@+id/edit" > 另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
當前名稱:listview的過濾-創(chuàng)新互聯(lián)
當前地址:http://weahome.cn/article/coeoho.html