Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make android button open a page number in java
    text
    copied!<p>I am new to java, and I am still learning, can anyone help in this respect in their spare time?I am trying to do a 10 page poem, just to start with.</p> <p>I have created buttons that look like a number pad, I am trying to make this number work when it has been pressed/clicked. I am able to make the numbers show when pressed. However, where I am having problems is how to make this number open another layout I have created with a number.</p> <p>Say I have created a layout and I want it to be page 7, how do I set it such that when number 7 is pressed (it shows the first line / title of the poem) and when the "Go" button is clicked, it opens the layout with poem number 7.</p> <p>Thank you</p> <p><strong>EDIT</strong></p> <p>I followed what you told me and now I have one layout and one fragment class.</p> <pre><code>`&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;android.support.v4.view.ViewPager android:id="@+id/text_fragment_pager" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;TextView android:id="@+id/tvpoem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; </code></pre> <p>`</p> <p>and the fragment java class is like:<br> public class PoemMapFrag extends Fragment</p> <pre><code>`{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragpoemsmap, container, false); TextView fragpageone = (TextView) view.findViewById(R.id.tvpoems); fragpageone.setText("Testing"); return view; } public View onCreateView1(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragpoemsmap, container, false); TextView fragpagetwo = (TextView) view.findViewById(R.id.tvpoems); fragpagetwo.setText("Yawning"); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); }` </code></pre>
 

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