2012-12-07 2 views
0

listView에서 제품 이름을 검색하려고하지만 검색 텍스트 필드의 일부 텍스트를 입력 한 후에 아무 것도 표시되지 않습니다. ArrayAdapter를 사용하지 않지만 ResourceCursorAdapter를 사용하고 있습니다.listView의 검색 기능

public void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       helper = new ComicsData(this); 
       helper.open(); 
       listSearch=(EditText)findViewById(R.id.inputSearch); 
       listSearch.addTextChangedListener(filterTextWatcher); 
       model = helper.getAllProduct(list); 
       startManagingCursor(model); 
       adapter=new ShoppingListAdapter(this, model); 

       listView.setAdapter(adapter); 
    } 
private TextWatcher filterTextWatcher=new TextWatcher(){ 

     public void afterTextChanged(Editable s) { 

      } 

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

      public void onTextChanged(CharSequence s, int start, int before, 
        int count) { 
       //String search=listSearch.getText().toString(); 
       //int textLength=search.length(); 
       adapter.getFilter().filter(s); 

      } 

     }; 

ShoppingListAdapter

class ShoppingListAdapter extends ResourceCursorAdapter { 

     private final String CN = null; 

     public ShoppingListAdapter(Context context, Cursor c) { 
      super(context, R.layout.productrow, c); 
      // TODO Auto-generated constructor stub 
     } 
    @Override 
     public void bindView(View row, Context context, Cursor c) { 
      // TODO Auto-generated method stub 


      listName = (TextView) row.findViewById(R.id.produtName); 
    listName.setText(helper.getProductName(c)); 

누구 내 실수를 알아?

답변

0

당신은 FilterQueryProvider의 인스턴스와 어댑터를 제공 할 필요가 호출에 따라 항목을 얻을. 이 공급자는 필터 쿼리를 사용하고 발견 된 모든 항목과 함께 커서를 반환합니다.

+0

내 검색어 부분에 LIKE 문을 사용해야합니까? – johnk

+0

@johnk 나는 그렇다고 생각한다. 도움을 청하는 –

+0

... 나는 개념을 얻었 .. – johnk

1

listSearch의 텍스트를 변경 한 후 텍스트 helper.getProducts(searchText);을 검색하고 adapter.notifyDataSetChanged()