There is an array of objects that has getters Category, Product, Quantity.

A list of categories is required, clicking on which opens a list with products and their number in the corresponding category.

For this, I sorted the array to get unique categories and brought them to the ListView , I also created a Fragment with a RecyclerView , which should get the String value from the ListView for which category to display the list ... actually from this and the question of how to transfer the ListView value to RecyclerView .

 public class ListDirectory extends Activity { private ListView mListViews; // public final static String EXTRA_SORT_ITEM = "extra_sort_item"; мои попытки private List<String> createListDirectories(){ DirectLab mDirectLab = DirectLab.get(this); return DirectLab.getCatName(mDirectLab);}//возвращает имена категорий без дублирования @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_view); mListViews = (ListView) findViewById(R.id.lvMain); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, createListDirectories()); mListViews.setAdapter(adapter); mListViews.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(ListDirectory.this, Direct_activity_list.class); // intent.putExtra(EXTRA_SORT_ITEM, createListDirectories().get(position)); мои попытки startActivity(intent); } });}} public class Direct_fragment_list extends Fragment { private RecyclerView mDirectRecyclerView; private DirectAdapter mAdapter; private Direct mDirect; public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.direct_fragment_list, container, false); mDirectRecyclerView = (RecyclerView) view.findViewById(R.id.direct_recycler_view); mDirectRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); updateUI(); return view; } private void updateUI() { DirectLab directLab = DirectLab.get(getActivity()); mAdapter = new DirectAdapter(DirectLab.getSortItem("ЗНАЧЕНИЕ КОТОРОЕ ТРЕБУЕТСЯ ПОЛУЧИТЬ ОТ LISTVIEW", directLab)); mDirectRecyclerView.setAdapter(mAdapter); } 

Well, the methods themselves for which sorted:

  public static List<String> getCatName(DirectLab directLab) { //возвращает уникальные названия категорий dir = new HashSet<>(); for (Direct d : directLab.getDirects()) { dir.add(d.getName_directory()); } catName = new ArrayList<>(dir); return catName; } public static List<Direct> getSortItem(String s, DirectLab directLab) { List<Direct> sortDirectory = new ArrayList<>(); for (Direct d : directLab.getDirects()) { if (d.getName_directory().equals(s)) sortDirectory.add(d); } return sortDirectory; } 

    1 answer 1

    everything turned out to be very simple, it was just required in the parameters mAdapter = new DirectAdapter(DirectLab.getSortItem("ЗНАЧЕНИЕ КОТОРОЕ ТРЕБУЕТСЯ ПОЛУЧИТЬ ОТ LISTVIEW", directLab)); pass getActivity().getIntent().getStringExtra(ListDirectory.EXTRA_SORT_ITEM);