Android app in eclipse - android

i've searched for days but cant find an answer, perhaps you guys can help.
I'm creating an android app in eclipse, it all works just one thing is bugging me.
this is my main.java:
package com.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Add Click listeners for all buttons
View firstButton = findViewById(R.id.btn_rassen);
firstButton.setOnClickListener(this);
View secondButton = findViewById(R.id.button2);
secondButton.setOnClickListener(this);
}
// Process the button click events
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_rassen:
Intent j = new Intent(this, Webscreen.class);
j.putExtra(com.test.Webscreen.URL,
"http://www.google.com/");
startActivity(j);
break;
case R.id.button2:
Intent k = new Intent(this, Webscreen.class);
k.putExtra(com.test.Webscreen.URL,
"http://notworkingurltotest.com");
startActivity(k);
break;
}
}
}
now when it calls the webview.java the page called shows up but not the buttons i created in the layout xml page. does anybody have any idea why this is?
your help is much appreciated!
ohw this is my webscreen.java
package com.test;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Webscreen extends Activity {
public static final String URL = "";
private static final String TAG = "WebscreenClass";
private WebView webview;
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.webscreen);
this.getIntent().getExtras();
this.webview = (WebView) findViewById(R.string.webview);
String turl = getIntent().getStringExtra(URL);
Log.i(TAG, " URL = "+turl);
WebView webview = new WebView(this);
setContentView(webview);
final Activity activity = this;
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onLoadResource (WebView view, String url) {
if (progressDialog == null) {
progressDialog = new ProgressDialog(activity);
progressDialog.setMessage("Bezig met laden...");
progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Intent myIntent = new Intent();
myIntent.setClassName("com.test", "com.test.Main");
startActivity(myIntent);
Toast.makeText(activity, "Laden van onderdeel mislukt, probeer het later nog eens! ", Toast.LENGTH_LONG).show();
progressDialog.show();
}
});
webview.loadUrl(turl);
}
}
webscreen.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- <1> -->
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<EditText android:id="#+id/url" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:lines="1"
android:layout_weight="1.0" android:hint="http://"
android:visibility="visible" />
<Button android:id="#+id/go_button" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="go_button" />
</LinearLayout>
<!-- <2> -->
<WebView
android:id="#string/webview"
android:layout_width="fill_parent"
android:layout_height="0dip"
/>
</LinearLayout>

Looks like you're creating a second webview and then setting that as the content view, so your R.layout.webscreen is replaced.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.webscreen);
this.getIntent().getExtras();
this.webview = (WebView) findViewById(R.string.webview);
String turl = getIntent().getStringExtra(URL);
Log.i(TAG, " URL = "+turl);
**WebView webview = new WebView(this);
setContentView(webview);**
.....
Edit:
I've just noticed something in your code, should the line that reads:
this.webview = (WebView) findViewById(R.string.webview);
Acutally be:
this.webview = (WebView) findViewById(R.**id**.webview);
Edit 2:
Just noticed another thing while I was making the project. The following in webscreen.xml:
android:id="#string/webview"
Should be:
android:id="#+id/webview"
Edit 3:
And another thing noticed in webscreen.xml:
android:layout_height="0dip"
Sure you want a 0 height?? ;-)

Related

How to get the content from webview and display it in a Textview

In my app, I need to display the content of a webview to the user via textView so that they can make changes for further use.
Can this be possible by reading the screen of the phone and displaying in a textView?
Or is there any function in webview which only retrieves the text shown in the URL to the user?
Also take help from here: https://developer.android.com
http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29
Get text content from a webview
Here is the code
strong text
package test.android.webview;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
public class WebviewTest2Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webView);
TextView contentView = (TextView) findViewById(R.id.contentView);
/* An instance of this class will be registered as a JavaScript interface */
class MyJavaScriptInterface
{
private TextView contentView;
public MyJavaScriptInterface(TextView aContentView)
{
contentView = aContentView;
}
#SuppressWarnings("unused")
public void processContent(String aContent)
{
final String content = aContent;
contentView.post(new Runnable()
{
public void run()
{
contentView.setText(content);
}
});
}
}
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJavaScriptInterface(contentView), "INTERFACE");
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url)
{
view.loadUrl("javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);");
}
});
webView.loadUrl("http://MIH.blogspot.com");
}
}
file.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
<TextView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
</LinearLayout>

adjusting dimensions of alert in android

I am making a basic app which has got an alert which would show up at the time the app is started. This alert has got a WebView in it and it covers almost the whole screen. Following are the questions I have in mind.
Now is it possible to adjust the dimensions of this alert ?
The url in the WebView in alert is set to 'http://www.google.com' let's say if some users are using my app and now I want them(users) to see a different webpage in the alert so how do I change the url without having them(users) update the app, how can I do it ?
MainActivity.java
package com.example.android.two;
import android.app.Dialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import com.example.android.two.R;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog dialog = new Dialog(this);
WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Notification");
alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
}
}
Yes, you can set dimensions for this alert dialog, by using custom layout for the Alert Dialog.
Please elaborate your second point.
You can use Custom Dialog Layout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<Button
android:layout_width="60dp"
android:layout_height="match_parent"
android:text="GO"
android:id="#+id/go"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/urlText"/>
</LinearLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/web">
</WebView>
</ScrollView>
</LinearLayout>
We will use WindowManager.LayoutParams to adjust the dimension or we can set the height and width for the linearLayout above.
The Activity Code will be:
import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
WebView wv;
EditText url;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_alert_dialog);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.CENTER;
url=(EditText) dialog.findViewById(R.id.urlText);
wv=(WebView) dialog.findViewById(R.id.web);
wv.setWebViewClient(new MyBrowser());
wv.getSettings().setLoadsImagesAutomatically(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://www.google.com");
Button go=(Button)dialog.findViewById(R.id.go);
go.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
wv.loadUrl("http://"+url.getText().toString());
}
});
dialog.getWindow().setAttributes(lp);
dialog.show();
}
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
Hope it Helps.
Cheers!

Spinner Appearing But not Disappearing

I am trying to implement a progress bar, that appears when loading the page and disappears when the page is finished loading. I have added on finish parameter but it seems that it is not being recognized.
Code
package com.test;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.ParseQuery;
import com.parse.PushService;
public class MainActivity extends Activity implements OnClickListener {
private Button push;
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "onReceive invoked!", Toast.LENGTH_LONG).show();
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
setContentView(R.layout.activity_main);
PushService.setDefaultPushCallback(this, MainActivity.class);
WebView webView = (WebView) findViewById(R.id.webView1);;
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.teqez.com/xx/ ");
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setBuiltInZoomControls(false);
push = (Button)findViewById(R.id.senPushB);
push.setOnClickListener(this);
}
private class HelloWebViewClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView webview, String url){
webview.loadUrl(url);
setProgressBarIndeterminateVisibility(true);
return true;
}
#Override
public void onPageFinished(WebView webview, String url){
super.onPageFinished(webview, url);
setProgressBarIndeterminateVisibility(false);
}
}
private class Callback extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return (true);
}
}
#Override
public void onBackPressed()
{
WebView webView = (WebView) findViewById(R.id.webView1);
if(webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}
#Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
}
#Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter(MyCustomReceiver.intentAction));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public void onClick(View v) {
JSONObject obj;
try {
obj = new JSONObject();
obj.put("alert", "hello!");
obj.put("action", MyCustomReceiver.intentAction);
obj.put("customdata","My message");
ParsePush push = new ParsePush();
ParseQuery query = ParseInstallation.getQuery();
// Push the notification to Android users
query.whereEqualTo("deviceType", "android");
push.setQuery(query);
push.setData(obj);
push.sendInBackground();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Layout
<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"
tools:context=".MainActivity" >
<Button
android:id="#+id/senPushB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher"
android:text="Check For Updates" />
<WebView
android:id="#+id/webView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:focusable="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
You do not invoke your custom private class
Change
webView.setWebViewClient(new WebViewClient());
to
webView.setWebViewClient(new HelloWebViewClient());

Android RuntimeException on setContentView

I am building an app for android, and while setting up my settingActivity and i get this error:
This happens when I start the activity. Before I moved the setContentView(R.layout.activity_setting); to the start of the onCreate() function, the application threw a NullPointerException at b.setOnCLickListener().
Now it throws a RuntimeException at the setContentView(); How do I resolve this?
01-18 14:28:59.116: E/AndroidRuntime(9463): java.lang.RuntimeException: Unable to start activity ComponentInfo{tk.yteditors.london2013/tk.yteditors.london2013.SettingActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-18 14:28:59.116: E/AndroidRuntime(9463):
at tk.yteditors.london2013.SettingActivity.onCreate(SettingActivity.java:27)
Java code:
package tk.yteditors.london2013;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SettingActivity extends PreferenceActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
setContentView(R.layout.activity_setting);
Button b = (Button) findViewById(R.id.sendAnswers);
b.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View pView) {
sendAnswers();
}
});
}
/**
* Set up the {#link android.app.ActionBar}, if the API is available.
*/
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.MenuSettings:
//boo
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void sendAnswers(){
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.activity_confirm_dialog);
dialog.setTitle("Antwoorden verzenden?");
((Button) dialog.findViewById(R.id.dialogNo)).setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
((Button) dialog.findViewById(R.id.dialogYes)).setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
EditText edit = (EditText) dialog.findViewById(R.id.sendAnswers);
packHTML(edit.getText().toString());
}
});
}
public void packHTML(String name){
try {
String fileDir = "/sdcard/LondonAnswers";
File dir = new File(fileDir);
dir.mkdirs();
String fileName = name +new Random().nextLong() +".html";
File file = new File(dir, fileName);
FileWriter fw = new FileWriter(file, false);
fw.append("<html>\n");
fw.append("<head><title>" +name +"'s antwoorden</title></head>\n");
fw.append("<body>\n");
fw.append("<h1>" +name +"'s antwoorden</h1>\n");
fw.append("</body>\n");
fw.append("</html>");
fw.close();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("webAdress", "file://" +fileDir +fileName);
startActivity(intent);
} catch (IOException e) {
Toast t = new Toast(this);
t.setText("Er is iets mis gegaan tijdens het maken van het bestand");
t.setDuration(Toast.LENGTH_SHORT);
t.show();
e.printStackTrace();
}
}
}
xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Antwoorden"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/sendAnswers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Verzend antwoorden" />
<Button
android:id="#+id/removeAnswers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Verwijder antwoorden" />
<Button
android:id="#+id/answersNYI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="NYI" />
</LinearLayout>
</ScrollView>
PreferenceActivity is-a ListActivity, and a ListActivity requires a layout which has a ListView with id #android:id/list. This is also shown in the exception you posted:
Your content must have a ListView whose id attribute is 'android.R.id.list'
Now, it seems that your code doesn't appear to be that of a regular Android preferences activity. Therefore you should change the extends PreferencesActivity to just extends Activity.

how to put a progress bar in an application using tabs

I have a main java file that sets up a series of tabs where each one calls a seperate activity in this case each activity is linked to a webpage. I am trying to implemente a progress bar in the tab activity that will show a progress bar for when a link is clicked on regardless of what tab is currently selected. I have a progress bar that i can use for a single activity but i cant get it to work for the tabs
i have the progress bar defined as
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
setContentView(R.layout.main );
webview = (WebView) findViewById(R.id.webview);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
MyActivity.setProgress(progress * 100);
if(progress == 100)
MyActivity.setTitle(R.string.app_name);
}
});
Which goes after oncreate()
Here is the main Java File
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.TabHost;
import android.widget.TextView;
public class UniversityofColorado extends TabActivity{
WebView webview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost host=getTabHost();
Resources res = getResources();
host.addTab(host.newTabSpec("one")
.setIndicator("",res.getDrawable(R.drawable.ic_tab_google))
.setContent(new Intent(this, Hello.class)));
host.addTab(host.newTabSpec("two")
.setIndicator("Colorado Main Site")
.setContent(new Intent(this, ColoradoMainSiteBrowser.class)));
host.addTab(host.newTabSpec("three")
.setIndicator("CULearn")
.setContent(new Intent(this, CULearnBrowser.class)));
host.addTab(host.newTabSpec("four")
.setIndicator("CULink")
.setContent(new Intent(this, CULinkBrowser.class)));
host.addTab(host.newTabSpec("five")
.setIndicator("MyCUInfo")
.setContent(new Intent(this, MyCUInfoBrowser.class)));
host.addTab(host.newTabSpec("six")
.setIndicator("", res.getDrawable(R.drawable.ic_tab_map))
.setContent(new Intent(this, CampusBrowser.class)));
host.addTab(host.newTabSpec("Seven")
.setIndicator("",res.getDrawable(R.drawable.ic_tab_notes))
.setContent(new Intent(this, NotesList.class)));
host.addTab(host.newTabSpec("eight")
.setIndicator("", res.getDrawable(R.drawable.ic_tab_help))
.setContent(new Intent(this, CampusBrowser.class)));
}
Here is one of the activities that the main java file calls
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class CampusBrowser extends Activity {
WebView webview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://amath.colorado.edu/department/Maps/bldgs.html");
}
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
XML File
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
If you could help me figure this out it would be appreciated
Hey this is exactly what I do in my webviews
In the onCreate method of the webview[in your case it may be your tabActivity] do this
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.webview_simple);
}
then in the webview client do this
private class MyWebViewClient extends WebViewClient {
public synchronized boolean shouldOverrideUrlLoading(WebView view, String url){
}// and all ur implementation
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
setProgressBarIndeterminateVisibility(false);
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
setProgressBarIndeterminateVisibility(true);
super.onPageStarted(view, url, favicon);
}
}
Hope it helps. I am overriding the onPageFinished and onPageStarted in the webview client. Its difficult to do it from onProgressChanged. I tried it but I found this to be simple.

Categories

Resources