1

I was able to download this form to my sdcard (from a given URL): enter image description here

My app can access this form via the android web view. My question is, how to save it to a text file after a user filled data to the form? I want to save in the text file the data inputted by the user, for instance:

Address: User address here
City: User City
Province: User Province here
Zip: 4342343
Phone: 4534534534
What is your biggest regret in your life? None.

will be saved to the text file... I'm kinda new to java and android dev.

BenMorel
  • 30,280
  • 40
  • 163
  • 285
Kris
  • 3,539
  • 14
  • 45
  • 66

1 Answers1

1

If you want to store the data locally, you should implement this form as a widget-based Activity rather than using a WebView.

If these values should be processed by a server, submit it like any other HTML form and let the server pick the values from the HTTP POST request.

EDIT

It is possible to attach a WebViewClient to the WebView, to allow methods in the WebView's Activity to be called from JavaScript. See sample code.

Your HTML file would need to contain JavaScript that runs when the "Submit" button is clicked, collects the contents of the form and then passes it to the WebViewClient.

(There might be an even easier way, see: Android Calling JavaScript functions in WebView)

Community
  • 1
  • 1
Tony the Pony
  • 37,471
  • 63
  • 170
  • 273
  • Thank you for your response Jen, yes I want to store it locally, hmm what do you mean by widget-based activity? – Kris May 19 '11 at 09:40
  • Instead of using HTML-based text fields, use a `TextView` for each field. Her's a tutorial: http://coenraets.org/blog/android-samples/androidtutorial/. Have a look at Step 5, which shows how to create the `Activity`: http://code.google.com/p/androidtutorial/source/browse/trunk/%20androidtutorial/EmployeeDirectory5/src/samples/employeedirectory/EmployeeDetails.java – Tony the Pony May 19 '11 at 09:44
  • But the text fields here is dynamic. They are downloaded from a URL (given by XML). Is there a way to convert those fields to android text views dynamically? – Kris May 19 '11 at 09:47
  • 1. How often do the questions change? 2. If a server generates the questions, wouldn't it make more sense for the server to process the responses? – Tony the Pony May 19 '11 at 09:50
  • I've just posted this related question: http://stackoverflow.com/questions/6056860/android-how-to-interact-with-the-content-in-a-webview – Tony the Pony May 19 '11 at 09:57
  • 1. The questions change frequently. 2. the devices will be offline once the questions were downloaded.. we want the app to be responsive coz if our server processes it, it is very slow... – Kris May 19 '11 at 10:06
  • Wow thanks for posting related question, you're so generous :) – Kris May 19 '11 at 10:08
  • 1
    It's an interesting topic, and it does look like a very good reason to use `WebView` – Tony the Pony May 19 '11 at 10:12