我正在尝试使用多个选择开发Listview
以及在Listview
中过滤文字。
下面是我的代码,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
for (int i = 0; i < 20; i++) {
items.add("abc " + i);
}
editText = (EditText) findViewById(R.id.editText);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//if (isOpened) {
if (listadapter != null)
listadapter.getFilter().filter(s.toString().trim());
//}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
listView = (ListView) findViewById(R.id.listView);
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
listadapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_multiple_choice, items);
listView.setAdapter(listadapter);
listView.setTextFilterEnabled(true);
}
检查图片