图片显示了导航抽屉中的ListView
,我添加了EditText
来过滤列表但是我无法实现这一点。请帮帮我怎么样!!!我的代码如下!谢谢!!!
public class MainActivity extends FragmentActivity {
private DrawerLayout mDrawerLayout;
ImageView home;
Fragment fragment = null;
TextView appname;
ListView listView;
// CustomAdapter customAdapter;
MyArrayAdapter myAdapter;
List<String> listData;
EditText inputSearch;
LinearLayout linearLayout;
CheckBox checkBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
home = (ImageView) findViewById(R.id.home);
home.setOnClickListener(homeOnclickListener);
appname = (TextView) findViewById(R.id.appname);
fragment = new MapFragment();
setUpDrawer();
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
myAdapter.getFilter().filter(s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
}
/**
*
* Get the names and icons references to build the drawer menu...
*/
private void setUpDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
mDrawerLayout.setDrawerListener(mDrawerListener);
listView = (ListView) findViewById(R.id.lvExp);
listView.setTextFilterEnabled(true);
linearLayout = (LinearLayout) findViewById(R.id.left_drawer_layout);
inputSearch = (EditText) findViewById(R.id.inputSearch);
checkBox = (CheckBox) findViewById(R.id.vechileCheck);
prepareListData();
myAdapter = new MyArrayAdapter(this, listData);
// setting list adapter
listView.setAdapter(myAdapter);
// fragment = new MapFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerLayout.closeDrawer(linearLayout);
}
View.OnClickListener homeOnclickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (mDrawerLayout.isDrawerOpen(linearLayout)) {
mDrawerLayout.closeDrawer(linearLayout);
} else {
mDrawerLayout.openDrawer(linearLayout);
}
}
};
private OnItemClickListener mDrawerItemClickedListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
switch (position) {
case 0:
fragment = new MapFragment();
break;
case 1:
fragment = new MapFragment();
break;
case 2:
fragment = new MapFragment();
break;
default:
return;
}
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, fragment).commit();
mDrawerLayout.closeDrawer(linearLayout);
}
};
// Catch the events related to the drawer to arrange views according to this
// action if necessary...
private DrawerListener mDrawerListener = new DrawerListener() {
@Override
public void onDrawerStateChanged(int status) {
}
@Override
public void onDrawerSlide(View view, float slideArg) {
}
@Override
public void onDrawerOpened(View view) {
}
@Override
public void onDrawerClosed(View view) {
}
};
private void prepareListData() {
listData = new ArrayList<String>();
// Adding child data
listData.add("Vechile-1");
listData.add("Vechile-2");
listData.add("Vechile-3");
listData.add("Vechile-4");
listData.add("Vechile-5");
listData.add("Vechile-6");
listData.add("Vechile-7");
listData.add("Vechile-8");
listData.add("Vechile-9");
listData.add("wakie");
}
}
public class MyArrayAdapter extends ArrayAdapter {
private Context _context;
private List<String> _listData;
public MyArrayAdapter(Context context, List<String> listData) {
super(context, -1, listData);
this._context = context;
this._listData = listData;
}
@Override
public int getCount() {
return this._listData.size();
}
@Override
public String getItem(int position) {
return this._listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
String headerTitle = (String) getItem(position);
if (view == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) view
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return view;
}
} ] 3