想要添加“搜索编辑”框。哪个可以从Listview中搜索员工姓名

时间:2011-11-04 11:27:42

标签: android android-layout android-manifest

在我的Employee目录项目中。我正在尝试添加列表视图的搜索编辑框,从我的名称中搜索Employee。 我使用以下代码在数据库的列表视图中显示员工列表。

    public class Contacts_list_sceen_2 extends Activity {
    protected ListView lv1; 
protected SQLiteDatabase db;
protected Cursor cursor;// cursor to query the database
protected ListAdapter adapter;
protected Button back_button;
protected Button about_button;
int position = 0;
TextView tm;
Bundle dataBundle = new Bundle();



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen2);
    this.setTitle("contactlistscreen2");
    Intent intent = getIntent();
final   int id = intent.getIntExtra("team_id", 1);


    DataStorage storage = DataStorage.getDataStorageHandle(this,
            Metidirectory.db_path);
    lv1 = (ListView) findViewById(R.id.ListView01);

    lv1.setAdapter(new CustomCursorAdaptor(this, storage.getEmpDetail(id)));
    lv1.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {


            cursor cursor = (Cursor)
                            parent.getItemAtPosition(position);



            Intent i = new Intent();
            i.putExtra("Data", new EmployeeBean(cursor));
            i.setClassName("com.guru.vinay",
            "com.guru.vinay.Database_display_activity");

            startActivity(i) ;
        }});

1 个答案:

答案 0 :(得分:0)

您必须对要搜索的EditText使用addTextChangeListener()。您可以使用此帖子来实现此功能。 http://android-helper.blogspot.in/2011/03/android-search-in-listview-example.html