Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The way to handle button clicks is to assign it an OnClickListener, like so :</p> <pre><code>button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { //start a new activity or replace the Fragment in view } }; </code></pre> <p>For your particular case, you could use <a href="http://developer.android.com/guide/components/fragments.html" rel="nofollow">Fragments</a> to show each page, using a <a href="http://developer.android.com/reference/android/app/FragmentTransaction.html#replace%28int,%20android.app.Fragment,%20java.lang.String%29" rel="nofollow">FragmentTransaction to replace the Fragment in view</a>. If you use an Activity, you would have 10 OnCLickListeners (one for each page), so I wouldn't advise it.</p> <p>Alternatively, you could just use a swipe gesture to switch Fragment, thus getting rid of your button. <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html" rel="nofollow">ViewPager</a> is designed for this, and you could use <a href="https://github.com/JakeWharton/Android-ViewPagerIndicator" rel="nofollow">Jake Wharton's ViewPagerIndicator</a> library to give a visual feedback of which page is in view.</p> <p>If you need me to clarify something, don't hesitate to ask ;-)</p> <p><strong>EDIT :</strong> As per your request, here's how I would do it using Fragments:</p> <p>Create a Fragment for each page. You can re-use the same layout each time, containing only a TextView with the text for your page, with width and height set as match_parent. In the fragment's onCreateView, you get a reference to the textview like so :</p> <pre><code>@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_page_layout, container, false); // Get references to layout elements pageTextView = (TextView) view.findViewById(R.id.article_paragraph_title); return view; } </code></pre> <p>and in the onActivityCreated :</p> <pre><code>pageTextView.setText(yourTextForThisPage); </code></pre> <p>In your activity you can either set a button to switch page, or use a ViewPager. The main idea is that the Activity will take care of switching Fragment, thus changing the text in view, since every time you change Fragment, a new Fragment should be created an replace the preceding one. You can use the links I provide above to get you started, or follow <a href="http://www.edumobile.org/android/android-beginner-tutorials/view-pager-example-in-android-development/" rel="nofollow">THIS TUTORIAL</a>, which seems to achieve more or less what I was trying to explain. I hope this clarifies a bit...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload