我在单独的活动中有两个单独的lists
。
MonthsActivity
具有prepareMonthData()
private void prepareMonthData() {
Calendar month = new Calendar("JANUARY");
monthList.add(month);
Calendar month = new Calendar("FEBRUARY");
monthList.add(month);
Calendar month = new Calendar("MARCH");
monthList.add(month);
// APRIL, MAY, JUNE, JULY, AUG, SEP, OCT , NOV and Finally....
Calendar month = new Calendar("DECEMBER");
monthList.add(month);
}
WeeksActivity
具有prepareWeeksData()
private void prepareWeeksData {
Calendar week = new Calendar("MONDAY");
weekList.add(week);
Calendar week = new Calendar("TUESDAY");
weekList.add(week);
// Wednesday, Thursday, Friday, Saturday and Finally ...
Calendar week = new Calendar("SUNDAY");
weekList.add(week);
}
我在以下两个活动中都实现了搜索视图
OnCreate
方法
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.months);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
// editTextSearch = (EditText) findViewById(R.id.editTextSearch);
mAdapter = new Adapter(this,monthList, this);
RecyclerView.LayoutManager mLayoutManager = new
LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
// row click listener
recyclerView.addOnItemTouchListener(new
RecyclerTouchListener(getApplicationContext(), recyclerView, new
RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
Calendar month = mAdapter.getMonthsList().get(position);
months = month.getTitle();
Toast.makeText(getApplicationContext(), months + " is selected!", Toast.LENGTH_SHORT).show();
view.getContext().startActivity(new Intent(view.getContext(),Months.class));
}
@Override
public void onLongClick(View view, int position) {
}
}));
prepareMonthData();
}
onCreateOptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.actionsearch)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
searchView.setMaxWidth(Integer.MAX_VALUE);
return super.onCreateOptionsMenu(menu);
// listening to search query text change
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// filter recycler view when query submitted
mAdapter.getFilter().filter(query);
return false;
}
@Override
public boolean onQueryTextChange(String query) {
// filter recycler view when text is changed
mAdapter.getFilter().filter(query);
return false;
}
});
return true;
}
..它完美搜索月份。.而其他活动则完美搜索星期..
现在,我想添加一个搜索视图,其中可以在我的MainActivity中搜索两个列表(月和周日)。即,如果用户搜索JANUARY或MONDAY,则该列表应过滤并显示结果..当列表处于单独的活动中时如何执行此操作...列表位于prepareMonthData()
中的名称MonthsActivity
和prepareWeekData()
PS:我尝试通过intent
方法中的MonthsActivity
将WeeksActivity
的String查询传递给onQueryTextChange
,但是当TextChanges时它会启动WeeksActivity
...