如何将搜索添加到列表视图android,将项目排序为u类型

cav*_*llo 0 search android listview

我有一个带有搜索栏的列表视图,我想在编辑文本中键入文本时对项目进行排序.我一直试图这样做,但是无法完成,你能帮我做吗?我要感谢你提前感谢

bin*_*dal 5

请参考此代码

package com.android.swfPlayer;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class SwfAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    private EditText edtField;
    ListView l1;
    ArrayList<String> array = new ArrayList<String>();
    ArrayList<String> type_name_copy = new ArrayList<String>();
    String[] array1 = { "abd", "bcd", "cdg", "sada", "fs", "fsf", "fsf" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        array.add("abd");
        array.add("bcd");
        array.add("cdg");
        array.add("sada");
        array.add("abd");
        array.add("fs");
        array.add("fsf");
        array.add("afsf");

        l1 = (ListView) findViewById(R.id.listView1);
        edtField = (EditText) findViewById(R.id.editText1);
        listUpdate(array);

        edtField.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            @Override
            public void afterTextChanged(Editable theWatchedText) {
                ArrayList<String> type_name_filter = new ArrayList<String>();

                String text = theWatchedText.toString();

                for (int i = 0; i < array.size(); i++) {

                    if ((array.get(i).toLowerCase()).contains(text
                            .toLowerCase())) {
                        type_name_filter.add(array.get(i));

                    }
                }

                type_name_copy = type_name_filter;

                listUpdate(type_name_copy);
            }
        });

    }

    public void listUpdate(ArrayList<String> data) {
        l1.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data));

    }
}
Run Code Online (Sandbox Code Playgroud)