UPD
In general, according to the advice - I tried to do it through ViewPager and Fragments - everything ViewPager out, but the question of collecting information remained.

How to get information from the View , which is not displayed on the screen? Because If I understood correctly, View (as well as activations, tabs, etc.)? which is not currently on the screen - does not exist (null).

Total - 4 fragments, each has a Checkbox , EditText , etc.

The submit button is in the MainActivity . Just how to access fragments from it that are not displayed on the screen — I cannot understand.

Mainactivity.java:

 public class MainActivity extends AppCompatActivity implements View.OnClickListener { static final String TAG = "myLogs"; static final int PAGE_COUNT = 4; ViewPager pager; PagerAdapter pagerAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter); Button btn = (Button) findViewById(R.id.button); btn.setOnClickListener(this); } private class MyFragmentPagerAdapter extends FragmentPagerAdapter { public MyFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return PageFragment.newInstance(position); } @Override public int getCount() { return PAGE_COUNT; } @Override public CharSequence getPageTitle(int position) { String title = null; switch (position){ case 0: title = "Users"; break; case 1: title = "System"; break; case 2: title = "IO"; break; case 3: title = "Other Text"; break; } return title; } } @Override public void onClick(View view) { EditText et = (EditText) pager.findViewById(R.id.user_phone_1_et); EditText et2 = (EditText) pager.findViewById(R.id.z1_alarm_et); et2.setText(et.getText().toString()); } } 

Pagefragment.java

 public class PageFragment extends Fragment { static final String ARGUMENT_PAGE_NUMBER = "arg_page_number"; int pageNumber; int backColor; static PageFragment newInstance(int page) { PageFragment pageFragment = new PageFragment(); Bundle arguments = new Bundle(); arguments.putInt(ARGUMENT_PAGE_NUMBER, page); pageFragment.setArguments(arguments); return pageFragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = null; switch (pageNumber) { case 0: view = inflater.inflate(R.layout.users, null); break; case 1: view = inflater.inflate(R.layout.system, null); break; case 2: view = inflater.inflate(R.layout.input_output, null); break; case 3: view = inflater.inflate(R.layout.other_text, null); break; } return view; } } 

First fragment

4 fragment

  • I do not understand what needs to be done and what is the problem? How can I get data if it is not there and the activation (tab) has not yet been created. describe the problem more clearly please. - Shwarz Andrei
  • 3
    The only correct solution is to stop using technologies that were outdated in the days of the Vikings, and start using ViewPager and fragments. - Vladyslav Matviienko
  • corrected, and I understand another question in ViewPager for different pages - is one activity being used? - Yura Geyts
  • Look through the tutorial on ViewPager , and everything will become clear. - Vladyslav Matviienko

2 answers 2

Information that is not currently displayed on the screen, but will be needed in the future, needs to be saved to entities that are independent of the life cycle of the activit \ fragments - in a Bundle, database, SharedPreferences, xml file or a collection of model objects. The specific method is chosen based on the tasks to be solved. Then the necessary information is retrieved from the repository, and not from View.

In the Bundle, the data is placed during short-term state saving, based on the fact that they need to be returned to the current location - the device turns, moving back and forth along the stack. This method has limitations on the amount of stored information (it is believed that it is limited to 1Mb ) and on the storage time (as a maximum - the current session). This is a kind of intermediate buffer and, as a rule, is not intended to move information between objects.

In the external storage (database, file, SharedPreferences) data is placed for long-term storage when you need to restore them after the application is closed.
For ease of access, SharedPreferences are much simpler, but they have limitations on the types of stored data and, generally, are not intended for intermediate storage of states, and more for infrequently changing settings, such as application settings.
With a large amount of data, the preference is for the database.

For storing intermediate states within a single object (such as aktiviti) it is convenient to use a model object that stores the current state of its child elements (data. Entered in fragments). The object is created when creating an activit and then the fragments record their information in it as it arrives, and also take it when the fragment is recreated in order to restore what has already been entered before. This method is valid within one launch of the activation. When you exit the activation data will be lost, so if they are required when returning for activation, you need to save them in a more reliable storage before exiting (file, database). It is also necessary to foresee the processing of device turns and the preservation of the model object itself in this case — this is either serialization and placement in the Bundle, or such a method .

  • Tell me, and if in the database in 1 table there are 40 cells for writing, is it possible to write 7 values ​​from 1 fragment, then in the second fragment, add 8 more, etc.? - Yura Geyts
  • @YuraGeyts Your database - as you see fit, write. Although the book with 1000 pages is written for working with the DBMS, how to write the values ​​there and organize the whole thing. Usually the tables are organized according to some structural characteristic, and they do not pile everything in one. In your case, I would stop at SharedPreferences - pavlofff

bind to the TabHost LocalActivityManager, example:

 LocalActivityManager localActMgr = new LocalActivityManager(this, false); localActMgr.dispatchCreate(savedInstanceState); TabHost tabs = (TabHost) findViewById(R.id.tabhost); tabs.setup(localActMgr); 

Further, in any activity of the successor, you can refer to the rest, an example is activity_one and activity_two you need to get the data activity_one in activity_two: the parent Activity Activity object LocalActivityManager must be public

 ParentActivity parentActivity = (ParentActivity) this.getParent(); parentActivity.localActMgr.getActivity(//Здесь String id - вашего наследника//);