how to open html file in widget frame

Put your problem here if it does not fit any of the other categories.

how to open html file in widget frame

Postby sandesh » Mon Mar 10, 2008 9:27 am

can anyone guide me in opening html/javascript file using widget
sandesh
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 07, 2008 11:12 am

Top

Postby plusminus » Mon Mar 10, 2008 9:20 pm

Hello sandesh,

you should provide some more details on what you want to do.
Maybe this helps:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. WebView view = new WebView(something);
  2.  
  3. view.getSettings().setJavaScriptEnabled(true);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

html page

Postby sandesh » Tue Mar 11, 2008 7:32 am

plusminus wrote:Hello sandesh,

you should provide some more details on what you want to do.
Maybe this helps:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. WebView view = new WebView(something);
  2. view.getSettings().setJavaScriptEnabled(true);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus



thanks plusminus
i want to open
In a frame html page http://openlayers.org/viewer

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.android.frame;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Color;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.view.View.OnClickListener;
  9. import android.webkit.WebView;
  10. import android.widget.Button;
  11. import android.widget.FrameLayout;
  12. import android.widget.LinearLayout;
  13.  
  14. public class frame extends Activity implements OnClickListener
  15. {
  16.     private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
  17.     private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
  18.     private Button buttonText;
  19.     private Button buttonButton;
  20.     private FrameLayout frameLayout;
  21.  
  22.     @Override public void onCreate(Bundle icicle)
  23.     {
  24.         super.onCreate(icicle);
  25.  
  26.         LinearLayout linearLayout = new LinearLayout(this);
  27.         linearLayout.setOrientation(LinearLayout.VERTICAL);
  28.         setContentView(linearLayout);
  29.  
  30.  
  31.         LinearLayout btnLinearLayout = new LinearLayout(this);
  32.         btnLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
  33.  
  34.         buttonText = new Button(this);
  35.         buttonText.setText("Text");
  36.         buttonText.setOnClickListener(this);
  37.  
  38.         buttonButton = new Button(this);
  39.         buttonButton.setText("Button");
  40.         buttonButton.setOnClickListener(this);
  41.  
  42.         btnLinearLayout.addView(buttonText, createParam(WC, WC));
  43.         btnLinearLayout.addView(buttonButton, createParam(WC, WC));
  44.  
  45.         frameLayout = new FrameLayout(this);
  46.         frameLayout.setBackgroundColor(Color.WHITE);
  47.  
  48.         linearLayout.addView(btnLinearLayout, createParam(FP, WC));
  49.         linearLayout.addView(frameLayout, createParam(200, 100));
  50.     }
  51.  
  52.     private LinearLayout.LayoutParams createParam(int w, int h){
  53.         return new LinearLayout.LayoutParams(w, h);
  54.     }
  55.  
  56.     private ViewGroup.LayoutParams createViewGroupParam(int w, int h){
  57.         return new ViewGroup.LayoutParams(w, h);
  58.     }
  59.  
  60.     public void onClick(View v) {
  61.         if (v == buttonText){
  62.                 WebView view = new WebView(this);
  63.                 view.getSettings().setJavaScriptEnabled(true);
  64.                 view.loadData("http://openlayers.org/viewer/", "text/html", "utf-8");
  65.            // TextView text = new TextView(this);
  66.           //  text.setText("");
  67.           // text.setTextColor(Color.RED);
  68.          //   frameLayout.addView(view, createViewGroupParam(WC, WC));
  69.         }else if (v == buttonButton){
  70.             Button button = new Button(this);
  71.             button.setText("Button");
  72.             frameLayout.addView(button, createViewGroupParam(WC, WC));
  73.            
  74.         }
  75.     }
  76. }
Parsed in 0.046 seconds, using GeSHi 1.0.8.4
sandesh
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 07, 2008 11:12 am

Postby plusminus » Tue Mar 11, 2008 9:48 am

Hello sandesh,

you are probably looking for [font=Lucida Console].loadUrl(String url);[/font]

Let us know whether you get it displayed.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

html page

Postby sandesh » Tue Mar 11, 2008 12:28 pm

plusminus wrote:Hello sandesh,

you are probably looking for [font=Lucida Console].loadUrl(String url);[/font]

Let us know whether you get it displayed.

Regards,
plusminus


hello plusminus i m getting NullPointerException error

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onClick(View v) {
  2.         if (v == buttonText){
  3.           WebView view = new WebView(this);
  4.           view.getSettings().setJavaScriptEnabled(true);
  5.           view.loadUrl("http://openlayers.org/viewer/");
  6.            // TextView text = new TextView(this);
  7.           //  text.setText("");
  8.           // text.setTextColor(Color.RED);
  9.          //   frameLayout.addView(view, createViewGroupParam(WC, WC));
  10.         }else if (v == buttonButton){
  11.             Button button = new Button(this);
  12.             button.setText("Button");
  13.             frameLayout.addView(button, createViewGroupParam(WC, WC));
  14.            
  15.         }
  16.     }
  17. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
sandesh
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 07, 2008 11:12 am

Re: html page

Postby plusminus » Tue Mar 11, 2008 3:03 pm

Hello sandesh,

sandesh wrote:hello plusminus i m getting NullPointerException error

my telepathic helping-skills are on holidays currently.

So where is the NPE thrown :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Re: html page

Postby sandesh » Wed Mar 12, 2008 6:47 am

plusminus wrote:Hello sandesh,

sandesh wrote:hello plusminus i m getting NullPointerException error

my telepathic helping-skills are on holidays currently.

So where is the NPE thrown :?:

Regards,
plusminus



NullPointerException-- linearLayout.addView(webview, createParam(wc, wc));

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.android.frame;
  2.  
  3.  
  4. import java.net.URL;
  5.  
  6. import android.app.Activity;
  7. import android.graphics.Color;
  8. import android.net.Uri;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.view.View.OnClickListener;
  13. import android.webkit.WebView;
  14. import android.widget.Button;
  15. import android.widget.FrameLayout;
  16. import android.widget.LinearLayout;
  17. //import android.widget.TextView;
  18.  
  19. public class frame extends Activity implements OnClickListener
  20. {
  21.     private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
  22.     private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
  23.     private Button buttonText;
  24.     private Button buttonButton;
  25.     private FrameLayout frameLayout;
  26.     private WebView webview;
  27.  
  28.    
  29.     @Override public void onCreate(Bundle icicle)
  30.     {
  31.         super.onCreate(icicle);
  32.  
  33.         LinearLayout linearLayout = new LinearLayout(this);
  34.         linearLayout.setOrientation(LinearLayout.VERTICAL);
  35.         setContentView(linearLayout);
  36.  
  37.  
  38.         LinearLayout btnLinearLayout = new LinearLayout(this);
  39.         btnLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
  40.  
  41.         buttonText = new Button(this);
  42.         buttonText.setText("Text");
  43.         buttonText.setOnClickListener(this);
  44.  
  45.         buttonButton = new Button(this);
  46.         buttonButton.setText("Button");
  47.         buttonButton.setOnClickListener(this);
  48.  
  49.         btnLinearLayout.addView(buttonText, createParam(WC, WC));
  50.         btnLinearLayout.addView(buttonButton, createParam(WC, WC));
  51.  
  52.         frameLayout = new FrameLayout(this);
  53.         frameLayout.setBackgroundColor(Color.WHITE);
  54.        
  55.        
  56.        
  57.         linearLayout.addView(btnLinearLayout, createParam(FP, WC));
  58.         linearLayout.addView(frameLayout,createParam(400, 200));
  59.         linearLayout.addView(webview, createParam(wc, wc));
  60.        
  61.     }
  62.  
  63.     private LinearLayout.LayoutParams createParam(int w, int h){
  64.         return new LinearLayout.LayoutParams(w, h);
  65.     }
  66.  
  67.     private ViewGroup.LayoutParams createViewGroupParam(int w, int h){
  68.         return new ViewGroup.LayoutParams(w, h);
  69.     }
  70.  
  71.     public void onClick(View v) {
  72.        if (v == buttonText){
  73.            
  74.         webview = new WebView(this);
  75.         webview.loadUrl("http://openlayers.org/viewer/");
  76.         setContentView(webview);
  77.        
  78.        //       TextView text = new TextView(this);
  79.          //   text.setText("this is text");
  80.            //text.setTextColor(Color.RED);
  81.            frameLayout.addView(webview, createViewGroupParam(WC, WC));
  82.         }else if (v == buttonButton){
  83.             Button button = new Button(this);
  84.             button.setText("Button");
  85.             frameLayout.addView(button, createViewGroupParam(WC, WC));
  86.            
  87.         }
  88.     }
  89. }
Parsed in 0.047 seconds, using GeSHi 1.0.8.4
sandesh
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 07, 2008 11:12 am

Postby plusminus » Wed Mar 12, 2008 7:20 pm

Hello sandesh,

[font=Lucida Console]onCreate(...)[/font] is the very first method of your Activity, being called and in that function you cannot call this line:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. linearLayout.addView(webview, createParam(wc, wc));
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
because webView is still null :!:

You initialize it only in [font=Lucida Console]onClick(...)[/font].

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests