获取在主类中传递的全局变量到静态类 - Android

时间:2016-03-01 01:07:09

标签: java android variables internal-storage

我得到了一个包含全局变量和PageAdapter静态类的代码。我到处寻找并没有找到答案。

我想获取userG变量,即在内部存储中加载标签。这是代码:

public class FormActivity extends AppCompatActivity {

    ActivityFormPageAdapter mActivityFormPageAdapter;
    ViewPager mViewPager;
    static String userG;

    public void onCreate(Bundle savedInstaceState) {
        super.onCreate(savedInstaceState);
        setContentView(R.layout.form_access);

        mActivityFormPageAdapter = new ActivityFormPageAdapter(getSupportFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.pages);
        mViewPager.setAdapter(mActivityFormPageAdapter);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabsform);
        tabLayout.setupWithViewPager(mViewPager);
        int i = Color.GRAY;
        tabLayout.setSelectedTabIndicatorColor(i);
        tabLayout.setSelectedTabIndicatorHeight(6);
    }
    public String getData(View view) throws IOException {
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            String MODEPROFILE = "mode_profile";
            FileInputStream fis = openFileInput(MODEPROFILE);
            int c;
            String userD = "";
            while ((c = fis.read()) != -1) {
                        userD = userD + Character.toString((char) c);
                    }
            Toast.makeText(getBaseContext(), userG, Toast.LENGTH_LONG).show();
            fis.close();
            userG = userD;
        return userG;
    }

    public static class ActivityFormPageAdapter extends FragmentStatePagerAdapter {

        public ActivityFormPageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            Fragment fragment = new FormObjectFragment();
            Bundle args = new Bundle();
            args.putInt(FormObjectFragment.ARG_OBJECT, i + 1);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "PERSONAL" + userG;
                case 1:
                    return "SERVICES";
                case 2:
                    return "APP ACCESS";
            }
            return null;
        }

        public static class FormObjectFragment extends Fragment {
            public static final String ARG_OBJECT = "object";

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.fragment_form, container, false);
                Bundle args = getArguments();
                String i = Integer.toString(args.getInt(ARG_OBJECT));
                if (i == Integer.toString(1)) {
                    //Toast.makeText(getContext(), , Toast.LENGTH_LONG).show();
                    rootView.findViewById(R.id.personal).setVisibility(View.VISIBLE);
                }
                if (i == Integer.toString(2)) {
                    rootView.findViewById(R.id.services).setVisibility(View.VISIBLE);
                }
                if (i == Integer.toString(3)) {
                    rootView.findViewById(R.id.appaccess).setVisibility(View.VISIBLE);
                }

                /*((TextView) rootView.findViewById(R.id.textform)).setText(Integer.toString(args.getInt(ARG_OBJECT)));*/
                return rootView;
            }
        }
    }
}

我正在使用(View view)来测试内部存储,但是当我调用getData()时它总是出现Null。这就是我把Charsequence放入变量的原因,看它是否会到来。但没有任何结果。总是空的。

任何人都可以帮助我?

0 个答案:

没有答案