您好,我有一个类似于以下image的菜单标签,在这里我需要过滤回收站中的产品。因此,现在有了在活动中进行搜索的工具栏,并在片段中添加了我需要过滤的回收者,当使用过滤来获取片段中的内容时,我就会停滞不前,可以通过某种方式在两者之间进行交互并可以执行我的过滤。
我的活动菜单标签
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_products1);
showToolbar("Productos", true);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("Productos"));
tabLayout.addTab(tabLayout.newTab().setText("Combos"));
searchView = (MaterialSearchView) findViewById(R.id.search_view);
final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager1);
PagerAdapter adapter = new ViewPagerAdapter1(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//Do some magic
Log.w("TAG", "Click1");
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//Do some magic
Log.w("TAG", "Click2");
return false;
}
});
searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
//Do some magic
showToolbar("", false);
Log.w("TAG", "Click3");
}
@Override
public void onSearchViewClosed() {
Log.w("TAG", "Click4");
showToolbar("Productos", true);
//Do some magic
}
});
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
int position = tab.getPosition();
viewPager.setCurrentItem(position);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
// Toast.makeText(Products1Activity.this, "Unselected -> "+tab.getText(), Toast.LENGTH_SHORT).show();
SendParametro();
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
// Toast.makeText(Products1Activity.this, "Reselected -> "+tab.getText(), Toast.LENGTH_SHORT).show();
SendParametro();
}
});
}
我的Fragmet回收站:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
showProgressDialog();
rootView = inflater.inflate(R.layout.fragment_products, container, false);
addMyCart = (Button) rootView.findViewById(R.id.addMyCart);
db = FirebaseDatabase.getInstance().getReference();
user = FirebaseAuth.getInstance().getCurrentUser();
MycategoriesCard = new ArrayList<MyCartProducts>();
gson = new Gson();
preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String savedList = preferences.getString("MyProductsCardList","");
Type type = new TypeToken<List<MyCartProducts>>(){}.getType();
MyProductsCardList = gson.fromJson(savedList,type);
mMyProducts = new ArrayList<>();
mMyProducts = this.getAllProducts();
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_products);
mLayoutManager = new LinearLayoutManager(getContext());
mAdapter = new MyAdapterProducts1(mMyProducts, R.layout.my_recycler_products1, new MyAdapterProducts1.OnItemClickListener() {
@Override
public void onItemClick(MyProducts myProducts, int position) {
}
@Override
public void onClickMore(MyProducts myProducts, int position, int contadorProd, String name, double soles) {
}
public void onClickLess(int contadorProd) {
String cadena = Integer.toString(contadorProd);
text_count.setText(cadena);
}
public void onClickReservar(int contadorProd) {
String cadena = Integer.toString(contadorProd);
text_count.setText(cadena);
Log.w(TAG,"contadorProd: " + contadorProd);
}
});
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
return rootView;
}