2012-09-09 3 views
0

에 검색 기능 추가 : tuto안드로이드이 자습서 다음 ListView에

내가 내 ListActivity 내로 글고 치기와 검색 functionnality을 만들고 싶어. 너무 그것을 만들 수 있도록

// Listview Data 
    String products[] = {"Dell Inspiron", "HTC One X", "HTC Wildfire S", "HTC Sense", "HTC Sensation XE", 
          "iPhone 4S", "Samsung Galaxy Note 800", 
          "Samsung Galaxy S3", "MacBook Air", "Mac Mini", "MacBook Pro"}; 

    lv = (ListView) findViewById(R.id.list_view); 
    inputSearch = (EditText) findViewById(R.id.inputSearch); 

    // Adding items to listview 
    adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, products); 
    lv.setAdapter(adapter); 

    /** 
    * Enabling Search Filter 
    * */ 
    inputSearch.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { 
      // When user changed the Text 
      MainActivity.this.adapter.getFilter().filter(cs); 
     } 

     @Override 
     public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, 
       int arg3) { 
      // TODO Auto-generated method stub 

     } 

     @Override 
     public void afterTextChanged(Editable arg0) { 
      // TODO Auto-generated method stub 
     } 
    }); 

나는 것하지만 내 사용자 정의와 : ArrayAdapter와

편집 :

그건

이 튜토리얼은 그것을 할 수 있지만, 간단한 ArrayAdapter와를 사용하는 방법에 대해 설명합니다 이제는 내 객체의 toString() 반환 값을 사용하여 작업을 수행합니다. 나는 "와인"난 그냥 하나 개의 요소를 포함하는이 단어가 내 목록에있는 내 글고에서

:

이 지금은이 문제가 내 목록 :

----------------- 
--------- 
The god of wine and orange juice 
--------------- 
---------------------- 

그건 잘 작동하고 이제 결과에 "The God .."이 있습니다. 그러나 와인 뒤에 공간을두면 결과가 사라집니다.

+1

[여기] (http://stackoverflow.com/a/12268592/1531054) –

답변

0

ArrayAdapter에 원하는 것을 추가 할 수 있습니다. 즉, ArrayAdapter<MyObject>toString() 메서드를 사용하여 목록에 표시 할 내용을 설정하십시오.