2017-04-04 66 views
0

我在下面的sqlDataBase中創建一個表,並且想在其上放置search選項。我想從ListView中選擇與可搜索面板的單詞相匹配的自定義顏色的項目。 我該怎麼做?如何在listView上使用search在android中選擇匹配項?

MainActivity.java:

public class MainActivity extends AppCompatActivity { 
    private ListView listView; 
    private AddAdapter adapter; 
    private DataBaseClass classDB; 
    private SQLiteDatabase sqlDB; 

    public final static ArrayList<String> _id=new ArrayList<String>(); 
    public final static ArrayList<String> _name = new ArrayList<String>(); 
    public final static ArrayList<String> _info = new ArrayList<String>(); 

    private EditText search; 

    public String doneIntent; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     listView = (ListView) findViewById(R.id.ListView); 

     classDB =new DataBaseClass(this); 

    // search panel 
     search= (EditText) findViewById(R.id.search_panel); 
     search.addTextChangedListener(new TextWatcher() { 
      @Override 
      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

      } 

      @Override 
      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { 
       MainActivity.this.adapter.getFilter().filter(charSequence); 
      } 

      @Override 
      public void afterTextChanged(Editable editable) { 

      } 
     }); 
     } 

AddAdapter.class:

public class AddBankAdapter extends BaseAdapter { 
private Context context; 
private ArrayList<String> Bid, Bname, Binfo; 

public AddAdapter(Context c , ArrayList<String> id ,ArrayList<String> name, ArrayList<String> info){ 
context=c; 
Bid=id; Bname=name; Binfo=info; 
} 


@Override 
public int getCount() { 
    return Bid.size(); 
} 

@Override 
public Object getItem(int i) { 
    return null; 
} 

@Override 
public long getItemId(int i) { 
    return 0; 
} 

@Override 
public View getView(int i, View view, ViewGroup viewGroup) { 
    ... 
} 

什麼getFilter()? 我該如何着色這些物品?

回答

相關問題