我的应用程序有点问题。所以首先我的应用程序只是一个简单的标签应用程序,它在每个页面上显示不同的 web 视图。目前我只有主页作为 webview。我没有收到任何类型的错误,但是当我尝试打开并运行我的应用程序时,它突然关闭了。关于我如何最终使这个应用程序正常工作的任何建议
谢谢
Arrowactivity.java
package app.tabsample;
import android.app.Activity;
import android.os.Bundle;
/**
* @author Adil Soomro
*
*/
public class ArrowsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.arrowspage);
}
}
Optionsactivity.java
package app.tabsample;
import android.app.Activity;
import android.os.Bundle;
/**
* @author Adil Soomro
*
*/
public class OptionsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.optionspage);
}
}
Tabsample.java
package app.tabsample;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
/**
* @author Adil Soomro
*
*/
public class TabSample extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs() ;
}
private void setTabs()
{
addTab("Home", R.drawable.tab_home, WebViewActivity.class);
addTab("News", R.drawable.tab_search, OptionsActivity.class);
addTab("Workouts", R.drawable.tab_home, ArrowsActivity.class);
addTab("Nutrition", R.drawable.tab_search, OptionsActivity.class);
}
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}
webViewactivity.java
package app.tabsample;
import app.tabsample.R;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weblayout);
WebView wv = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
wv.setWebViewClient(new Callback());
wv.loadUrl("file:///android_asset/repmax.html");
}
private class Callback extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return(true);
}
}
}
arrowspage.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:text="Welcome"
android:layout_centerInParent="true" android:textSize="20sp"/>
</RelativeLayout>
weblayout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.webkit.WebView
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</android.webkit.WebView>
</RelativeLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1" />
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
tab_indicator.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="55dip"
android:layout_weight="1"
android:orientation="vertical"
android:background="@drawable/tab_indicator"
android:padding="5dp">
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/icon"
/>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
style="?android:attr/tabWidgetStyle"
/>
</RelativeLayout>
optionspage.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_width="fill_parent">
<EditText android:layout_alignParentLeft="true"
android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:hint="Search Text"/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentRight="true" android:text="Search"/>
</LinearLayout>
</RelativeLayout>