Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 7    Views: 85

Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
04/03/14 08:05 AM (10 years ago)

Android codeing help!!!

Can some Android ninja help me? I have an Main.xlm file in this file I have a webview banner. I need the code for my MainActivity.java file. I need the code for the webview. I want the webview to load a url and I need webview have AspectToFit or ScaleToFit function. The content I load in the URL have no meta tag for device scale.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
04/03/14 08:16 AM (10 years ago)
I'm about to go to bed, but this might help get you started… this is for fragments, not activity. although it might not matter. in your class declarations: private WebView webView = null; in your 'onCreate' method webView = (WebView) thisScreensView.findViewById(R.id.webView); webView.setBackgroundColor(0); webView.setInitialScale(0); webView.getSettings().setJavaScriptEnabled(true); // webView.loadUrl("file:///android_asset/BT_Docs/yourlocalfile.html"); OR webView.loadUrl("http://www.yourserver.com/yourdistantfile.html"); I'll look for something more elegant tomorrow if this doesn't work out for you. Cheers! -- Smug
 
Annonymous
Profile
04/03/14 09:53 AM (10 years ago)
Ha - you do sleep!
 
Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
like
04/04/14 05:41 AM (10 years ago)
SmugWimp it works. But I have some problem with if statement . I have a Radio app. The app have 3 Stations when I tap next station I want the webview to load a different URL. Then I need the webView Reload the URL every 15 sec. Can you help me with this?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
04/04/14 06:51 AM (10 years ago)
For the reload I'd suggest something like this: First, setup a 'Runnable' as your 'loop', set it for 15 seconds: private Runnable runThisURL = new Runnable() { @Override public void run() { /* refresh the URL */ webView.loadUrl("http://www.yourserver.com/yourdistantfile.html"); /* this next line causes the loop to delay in milliseconds */ handler.postDelayed(this, 15000); } }; Then, somewhere you'll want to call for it to start… private Handler handler = new Handler(); handler.postDelayed(runThisURL, 100); and eventually you may want to call for it to stop: handler.removeCallback(runThisURL) That should work, although it might require adding some libraries and stuff… letting the 'autofix' correct the missing libraries should do the job… but you get the idea, I hope. Cheers! -- Smug
 
Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
like
04/04/14 08:06 AM (10 years ago)
Thanks for this, but it don´t work for me. Android coding is so boring, its so stupid. :) Xcode is more fun and smart to programming on. If I send my source code to you, do you want to look at it?
 
Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
like
04/04/14 08:36 AM (10 years ago)
I add this for refreshing the page every 15 sec and this work. new Timer().schedule(new TimerTask(){ @Override public void run() { // TODO Auto-generated method stub webView.reload(); }}, 15000, 15000); But now I have to add some code to change URL when the user change radio station. ):
 
Mackimack
Apple Fan
Profile
Posts: 481
Reg: Dec 30, 2010
Sweden
14,310
like
04/04/14 10:19 AM (10 years ago)
Now I have fix everything. Now Im little grayer in my head. :)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.