Click here to Skip to main content
15,884,177 members
Home / Discussions / Android
   

Android

 
QuestionRe: How To Trigger Fragment From Button Inside Another Fragment Pin
David Crow3-Aug-17 2:30
David Crow3-Aug-17 2:30 
QuestionStatic linking of Android applications Pin
Daniel Pfeffer29-Jul-17 23:45
professionalDaniel Pfeffer29-Jul-17 23:45 
AnswerRe: Static linking of Android applications Pin
chipp_zanuff30-Jul-17 4:26
chipp_zanuff30-Jul-17 4:26 
GeneralRe: Static linking of Android applications Pin
Daniel Pfeffer30-Jul-17 9:07
professionalDaniel Pfeffer30-Jul-17 9:07 
QuestionCampaign attribution Pin
Anirudh Agrawal26-Jul-17 9:41
Anirudh Agrawal26-Jul-17 9:41 
AnswerRe: Campaign attribution Pin
Floyd Mayweather Conor McGregor watch1-Aug-17 20:00
Floyd Mayweather Conor McGregor watch1-Aug-17 20:00 
QuestionDoes anyone know... Pin
Mehdi Gholam22-Jul-17 18:44
Mehdi Gholam22-Jul-17 18:44 
AnswerRe: Does anyone know... Pin
Richard MacCutchan22-Jul-17 20:40
mveRichard MacCutchan22-Jul-17 20:40 
QuestionHow to send the added total marks to multiple activities in android Pin
Member 1309533820-Jul-17 23:48
Member 1309533820-Jul-17 23:48 
SuggestionRe: How to send the added total marks to multiple activities in android Pin
David Crow21-Jul-17 10:35
David Crow21-Jul-17 10:35 
Questiongif emoji Pin
Simran Sharma15-Jul-17 23:53
Simran Sharma15-Jul-17 23:53 
AnswerRe: gif emoji Pin
Richard MacCutchan16-Jul-17 1:32
mveRichard MacCutchan16-Jul-17 1:32 
Questionchat Pin
Simran Sharma16-Jul-17 0:48
Simran Sharma16-Jul-17 0:48 
AnswerRe: chat Pin
Richard MacCutchan16-Jul-17 1:32
mveRichard MacCutchan16-Jul-17 1:32 
AnswerRe: chat Pin
David Crow17-Jul-17 10:27
David Crow17-Jul-17 10:27 
Questionmake book reader with feature of search and go to page Pin
Ali_Abdelrhim10-Jul-17 2:08
Ali_Abdelrhim10-Jul-17 2:08 
Hi;

I am new to Android, and I am making a book reader (not for all books) but only for one textbook. I started with the demo for multi-pages in Android developers section and I added some text to it. My question is, is that the correct example I used (TextView)? here is my code:
I ma saving the strings in "String.xml" file.

Java
public class MainActivity extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    private SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);


     /* FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
          }
      });*/

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            PlaceholderFragment p = PlaceholderFragment.newInstance(1);

            
            return true;
        }

        return super.onOptionsItemSelected(item);
    }




    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

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

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            return PlaceholderFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            // Show 600 total pages.
            return 604;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "SECTION 1";
                case 1:
                    return "SECTION 2";
                case 2:
                    return "SECTION 3";
            }
            return null;
        }
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment  {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        private static final String ARG_PAGE_NUMBER = "page_number";

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();

            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.section_label);
           // textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
            //String page = "page"+getArguments().getInt(ARG_SECTION_NUMBER);
            //textView.setText(getString("R.string." + page));
            textView.setTextSize(20);
            int page_number_to_go =1;
            page_number_to_go = getArguments().getInt(ARG_SECTION_NUMBER);
            goToPage(textView, page_number_to_go);
           // Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
           // getSupportActionBar(toolbar);

            return rootView;
        }
        public void goToPage(TextView textView, int page_number){
            switch (page_number){
                case 1:
                    textView.setText(getString(R.string.page1));
                    // toolbar.setTitle("صفحة رقم 1");
                    break;
                case 2:
                    textView.setText(getString(R.string.page2));
                    // toolbar.setTitle("صفحة رقم 2");
                    break;
                case 3:
                    textView.setText(getString(R.string.page3));
                    // toolbar.setTitle("صفحة رقم 3");
                    break;
                case 4:
                    textView.setText(getString(R.string.page4));
                    break;
                case 5:
                    textView.setText(getString(R.string.page5));
                    break;
                case 6:
                    textView.setText(getString(R.string.page6));
                    break;
                case 7:
                    textView.setText(getString(R.string.page7));
                    break;
                case 8:
                    textView.setText(getString(R.string.page8));
                    break;
                case 9:
                    textView.setText(getString(R.string.page9));
                    break;
                case 10:
                    textView.setText(getString(R.string.page10));
                    break;
                case 11:
                    textView.setText(getString(R.string.page11));
                    break;
                case 12:
                    textView.setText(getString(R.string.page12));
                    break;
}

QuestionRe: make book reader with feature of search and go to page Pin
David Crow11-Jul-17 13:36
David Crow11-Jul-17 13:36 
AnswerRe: make book reader with feature of search and go to page Pin
Ali_Abdelrhim13-Jul-17 2:45
Ali_Abdelrhim13-Jul-17 2:45 
GeneralRe: make book reader with feature of search and go to page Pin
David Crow13-Jul-17 2:57
David Crow13-Jul-17 2:57 
Suggestionsystem ui failed Pin
Member 131159839-Jul-17 23:50
Member 131159839-Jul-17 23:50 
Questioncoding Pin
Member 132908393-Jul-17 21:01
Member 132908393-Jul-17 21:01 
AnswerRe: coding Pin
Richard MacCutchan3-Jul-17 21:26
mveRichard MacCutchan3-Jul-17 21:26 
Questionandroid studio Pin
Member 132908393-Jul-17 20:36
Member 132908393-Jul-17 20:36 
AnswerRe: android studio Pin
Richard MacCutchan3-Jul-17 21:25
mveRichard MacCutchan3-Jul-17 21:25 
SuggestionRe: android studio Pin
David Crow5-Jul-17 4:48
David Crow5-Jul-17 4:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.