I am attempting to make a 'table of contents' that is similar in feel to wikipedias as shown here.
I have a ScrollView
which contains many TextViews
. I have made a 'table of contents' that has clickable elements, but I cannot figure out how to make the ScrollView
scrollTo()
the right spot.
I attempted to convert the TextView
to a string, and use s.IndexOf()
, but it gives me the location of the text within the string, not within the ScrollView
. This behavour makes sense
I then tried to look at other ScrollView
methods to find something helpful, but ran out of ideas.
If I could find the IndexOf
the TextView
within the ScrollView
I could easily ScrollTo
that spot, but I cannot figure out how to do this.
Thanks, EDIT2: This is very similiar to hyperlinking to an inline anchor in HTML, using the # as described here.
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 TextView
with id KeyQuestionsTextView
and have it scroll down to the TextView
with id KeyQuestions
. I have made the onclick
listener for KeyQuestionsTextView
register the OnClick
event, but I do not know how to make the ScrollView
scroll to the right spot. I really need to just get the Y offset of the desired TextView
within the ScrollView
, as the ScrollTo
method is straightforward it seems.
The above example will be repeated for PhysicalExamTextView
DiagnosticReasoning
and Emergencies
. Those four elements compose my 'table of contents'.
<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" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/Intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Plat2Option1Intro" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#000000" />
<TextView
android:id="@+id/KeyQuestionsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/KeyQuestionsTitle" />
<TextView
android:id="@+id/PhysicalExamTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/PhysicalExamTitle" />
<TextView
android:id="@+id/DiagnosticReasoningTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/DiagnosticReasoningTitle" />
<TextView
android:id="@+id/EmergenciesTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/EmergenciesTitle" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#000000" />
<TextView
android:id="@+id/KeyQuestions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Plat2Option1KeyQuestions" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#000000" />
<TextView
android:id="@+id/PhysicalExam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Plat2Option1PhysicalExam" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#000000" />
<TextView
android:id="@+id/DiagnosticReasoning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Plat2Option1DiagReasoning" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#000000" />
<TextView
android:id="@+id/Emergencies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Plat2Option1Emergencies" />
</LinearLayout>
</ScrollView>