0

I have html files in this pattern.

<a name="header1"></a>
<h2>First Heading</h2>
<a>Some Text goes here</a><br/>
<br/>
<a name="header2"></a>
<h2>Second Heading</h2>
Some Text goes here<br/>
<br/>

Which Looks like this :


First Heading

Some Text goes here

Second Heading

Some Text goes here


In a ListView, I have the list of all the headers in the html file and based on which header the user selects, I bring the corresponding header to the top of the screen by doing view.loadUrl("javascript:window.location.hash='" + headerName + "'") in the custom WebViewClient's onPageFinished method and change the title of the screen in the titleBar to the headerName.

Now my problem is : If a user selects header1 in the ListView and scrolls down to header2, I need to know that the user is in the header2 section so that the title of the screen could be changed. How can I know which part of the html file is being shown on the screen?

Any help is appreciated.

500865
  • 6,920
  • 7
  • 44
  • 87

1 Answers1

0

I would use javascript on a setInterval() to monitor when the header was in view by tracking the window.scrollY and comparing it to the page position of the header (which you should likely calculate and cache). Hints on page position here. After that, update the URL of the window from javascript, and track it via your WebViewClient's methods, and you should be all set.

Sajid
  • 4,381
  • 20
  • 14
  • Actually, I do not have a good experience with Javascript. Can you elaborate a little bit. I dint understand what you mean by 'javascript on a setInterval()' – 500865 Oct 23 '11 at 18:21
  • Actually, it would be a better to user to use window.onscroll. So basically do window.onscroll = function() { /* check window.scrollY against the positions of the headers here */ }; This function will trigger every time the user scrolls. When your function gets called, update the document.location.href to have the right hash. – Sajid Oct 24 '11 at 05:02