在这个应用程序中,交易将首先根据来自片段的周期(月 - 年)进行过滤,我想要的第二个过滤器是过滤(基于交易类型,即仅信用)使用开关。
目前我有两个过滤器单独工作,但我无法弄清楚如何以及在第一个过滤器后在recyclerview中更新过滤列表的位置,并在其上应用第二个过滤器。
截至目前,当我应用第一个过滤器然后执行第二个过滤器时,recyclerview列表是原始列表而不是月份过滤列表。
点击此活动中的按钮,会打开片段,然后从中检索使用具有方法passDataToActivity()的界面选择的月份
使用recyclerview和switch的活动:
public class TransactionsActivity extends AppCompatActivity implements ActivityCommunicator{
SearchView searchtrans;
SearchView searchView ;
private RecyclerView recyclerView;
private Button monthButton, filterButton;
public static RecentTransAdapter mAdapter;
private Switch aSwitch;
boolean filtered;
public FragmentCommunicator fragmentCommunicator;
String dateSelected ;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transactions);
searchtrans = (SearchView) findViewById(R.id.searchTrans);
searchtrans.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mAdapter.getFilter().filter(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
mAdapter.getFilter().filter(newText);
return true;
}
});
recyclerView = (RecyclerView) findViewById(R.id.trans);
List<Transaction> newList = new ArrayList<Transaction>();
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
newList = Transaction.transactionList;
monthButton = (Button) findViewById(R.id.monthButton);
// filterButton = (Button) findViewById(R.id.filterButton);
aSwitch = (Switch) findViewById(R.id.switch1);
String currentMonth = "" ;
Calendar cal = Calendar.getInstance();
/* Date date = new Date();
cal.setTime(date);
*/
currentMonth = new SimpleDateFormat("MMMM").format(cal.getTime());
monthButton.setText(currentMonth);
monthButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
// FragmentTransaction ft = fm.beginTransaction();
MyFrag dFragment = new MyFrag();
// Show DialogFragment
dFragment.show(fm, "Dialog Fragment");
// fragmentCommunicator.passDataToFragment(mAdapter);
}
});
**mAdapter = new RecentTransAdapter(newList, this);**
**aSwitch.setOnCheckedChangeListener(new** CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
if (!isChecked) {
Log.d("notchecked","yo");
mAdapter.getFilter().filter("");
} else {
mAdapter.getFilter().filter("credit");
}
recyclerView.setAdapter(mAdapter);
}
});
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
}
@Override
public void passDataToActivity(String someValue,RecentTransAdapter recentTransAdapter) {
dateSelected = someValue;
//dateSelected = "someTest";
monthButton.setText(dateSelected);
mAdapter = recentTransAdapter ;
}
@Override
protected void onResume() {
super.onResume();
mAdapter.notifyDataSetChanged();
}
}