Note that there are some explanatory texts on larger screens.

plurals
  1. POClickable table of contents
    primarykey
    data
    text
    <p>I am attempting to make a 'table of contents' that is similar in feel to <a href="http://en.wikipedia.org/wiki/Proton" rel="nofollow">wikipedias as shown here.</a></p> <p>I have a <code>ScrollView</code> which contains many <code>TextViews</code>. I have made a 'table of contents' that has clickable elements, but I cannot figure out how to make the <code>ScrollView</code> <code>scrollTo()</code> the right spot. </p> <p>I attempted to convert the <code>TextView</code> to a string, and use <code>s.IndexOf()</code>, but it gives me the location of the text within the string, not within the <code>ScrollView</code>. This behavour makes sense</p> <p>I then tried to look at other <code>ScrollView</code> methods to find something helpful, but ran out of ideas.</p> <p>If I could find the <code>IndexOf</code> the <code>TextView</code> within the <code>ScrollView</code> I could easily <code>ScrollTo</code> that spot, but I cannot figure out how to do this.</p> <p>Thanks, EDIT2: This is very similiar to hyperlinking to an inline anchor in HTML, using the # <a href="http://www.w3schools.com/html/html_links.asp" rel="nofollow">as described here.</a></p> <p>EDIT: added my XML, this would seem to be the only important part of the code to make it more clear. The goal is to hit the <code>TextView</code> with id <code>KeyQuestionsTextView</code> and have it scroll down to the <code>TextView</code> with id <code>KeyQuestions</code>. I have made the <code>onclick</code> listener for <code>KeyQuestionsTextView</code> register the <code>OnClick</code> event, but I do not know how to make the <code>ScrollView</code> scroll to the right spot. I really need to just get the Y offset of the desired <code>TextView</code> within the <code>ScrollView</code>, as the <code>ScrollTo</code> method is straightforward it seems.</p> <p>The above example will be repeated for <code>PhysicalExamTextView</code> <code>DiagnosticReasoning</code> and <code>Emergencies</code>. Those four elements compose my 'table of contents'.</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Platform2_option1" &gt; &lt;ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/Intro" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/Plat2Option1Intro" /&gt; &lt;View android:layout_width="fill_parent" android:layout_height="1dip" android:background="#000000" /&gt; &lt;TextView android:id="@+id/KeyQuestionsTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/KeyQuestionsTitle" /&gt; &lt;TextView android:id="@+id/PhysicalExamTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/PhysicalExamTitle" /&gt; &lt;TextView android:id="@+id/DiagnosticReasoningTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/DiagnosticReasoningTitle" /&gt; &lt;TextView android:id="@+id/EmergenciesTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/EmergenciesTitle" /&gt; &lt;View android:layout_width="fill_parent" android:layout_height="1dip" android:background="#000000" /&gt; &lt;TextView android:id="@+id/KeyQuestions" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/Plat2Option1KeyQuestions" /&gt; &lt;View android:layout_width="fill_parent" android:layout_height="1dip" android:background="#000000" /&gt; &lt;TextView android:id="@+id/PhysicalExam" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/Plat2Option1PhysicalExam" /&gt; &lt;View android:layout_width="fill_parent" android:layout_height="1dip" android:background="#000000" /&gt; &lt;TextView android:id="@+id/DiagnosticReasoning" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/Plat2Option1DiagReasoning" /&gt; &lt;View android:layout_width="fill_parent" android:layout_height="1dip" android:background="#000000" /&gt; &lt;TextView android:id="@+id/Emergencies" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/Plat2Option1Emergencies" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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