Hello!

I have:

MainActivity ;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); viewPager = (ViewPager) findViewById(R.id.viewPager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tabLayout); tabLayout.setupWithViewPager(viewPager); } private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new Tab_Heads(), "ГЛАВЫ"); adapter.addFragment(new Tab_Bookmarks(), "ЗАКЛАДКИ"); viewPager.setAdapter(adapter); } 

Fragment CHAPTERS ;

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tab_heads, container, false); listView = (ListView) view.findViewById(R.id.listView); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( getActivity(), R.array.Heads, R.layout.list_line_items); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } }); return view; } 

In R.array.Heads I have more than 100 items, and I want to implement adding bookmarks. That is, either by calling the context menu, or by pressing the button, so that the selected item will be added to the "BOOKMARKS" fragment, and so that you can select any item and add it to the next tab "BOOKMARKS".

Also still interested ;

  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 0) Intent i = new Intent(getActivity, Head_1.class); startActivity(i); } }); 

Is it possible to implement this intent differently, since I have more than 100 chapters? Or will I need an if (position ==?) And prescribe an intent for each position, as shown in the code?

  • I didn’t go into the code much, but in this case, if can be replaced with switch-case . - s8am 4:34 pm
  • Storage of an array here is more of an academic nature, since when you exit the application, all your bookmarks will be lost. You need to store this information in permanent memory, such as a database. See, for example, this answer , how this can be implemented. You also need not to create 100 activations for each chapter, but only one to which you can transfer through the intent what chapter to display and change only the content. - pavlofff
  • @pavlofff, did I understand the implementation theory correctly, for example, I have a screen with the same two tabs, in both tabs I twist a sheet, I create a database, fill it with text, and then fill it with separate lines in a first tab, and set it on each item A button, by clicking on which, a sheet of a view in the second tab on the ID will receive a string and display it? - Int404 September
  • @pavlofff And also, how to search for the implementation of the method with the intent about which you speak? It turns out I get all the ID on the text I get in one activation, and through it I run xml content? That is, I will have 100xml of chapters, and one activity that will process them? Just the display is different in the xml chapters. - Int404 September
  • No, you do not need to create 100 xml. There are two activations - one with a list of chapters, the second to display text by chapter, which has a TextView in the markup. In the database you keep records: id, chapter, chapter contents. When you click on the list, you get the record ID, transfer this ID by intent to the second activation. In the second activation by the received ID, select from the database about the contents of the chapter and set the received text in TextView . See the implementation of the Master / Detail Flow pattern. If it is still not clear, create a new question for this issue. - pavlofff

0