2012-05-08 2 views
0

검색 가능한 연락처 종류의 앱을 만듭니다. 다음은 내 코드쿼리 완료 후 재배치 목록을 나열합니다.

public class EmployeeList extends Activity { 

    protected EditText searchText; 
    protected SQLiteDatabase db; 
    protected Cursor cursor, listcursor; 
    protected ListAdapter adapter; 
    protected ListView employeeList; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     db = (new DatabaseHelper(this)).getWritableDatabase(); 
     searchText = (EditText) findViewById (R.id.searchText); 
     employeeList = (ListView) findViewById (R.id.list); 

     listcursor = db.rawQuery("SELECT * FROM employee",null); 

     adapter = new SimpleCursorAdapter(
       this, 
       R.layout.employee_list_item, 
       listcursor, 
       new String[] {"firstName", "lastName", "title"}, 
       new int[] {R.id.firstName, R.id.lastName, R.id.title}); 
     employeeList.setAdapter(adapter); 
    } 

     public void search(View view) { 
      // || is the concatenation operation in SQLite 
        cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE firstName || ' ' || lastName LIKE ?", 
                new String[]{"%" + searchText.getText().toString() + "%"}); 
        adapter = new SimpleCursorAdapter(
            this, 
            R.layout.employee_list_item, 
            cursor, 
            new String[] {"firstName", "lastName", "title"}, 
            new int[] {R.id.firstName, R.id.lastName, R.id.title}); 
        employeeList.setAdapter(adapter); 

             } 

}

문제가 글고에서 단어를 삭제 한 후입니다. 이전 목록보기로 돌아 가야합니다. 즉, db의 모든 값을 표시해야합니다.

enter image description here

+0

@Jason 와트는 이해할 수 없습니다. – Satheesh

답변

2

대신 두 번째 커서를 사용하여, 당신은 많은 AutoCompleteTextView에 같이 ListView에 여러 업데이트를 수행 업데이트하기 위해 글고 치기와 FilterQueryProvider을 사용해야합니다.

또는 TextWatcher를 추가하고 길이가 0이 될 때마다 커서를 첫 번째 커서로 변경할 수 있습니다.