我有 3 个标签,点击时显示不同的内容。我希望他们在点击时打开某些活动。这些活动只不过是需要显示的数据库报告。我使用 Web 视图并在 API 级别 11 的模拟器上运行良好,但Web page not found
在我的设备上显示 API 级别 10 时出现错误。此外,这些选项卡仅在单击其他选项卡并返回第一个选项卡后才会显示数据。有没有办法可以直接启动活动而不是使用网络视图?
任何帮助表示赞赏。
xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout1"
android:orientation="vertical"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" ></TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabs1"
android:orientation="vertical"
>
<WebView
android:id="@+id/txtGetFuelInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Get info from Database" />
<TextView
android:id="@+id/txtGetFuel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabs2"
android:orientation="vertical"
>
<WebView
android:id="@+id/txtMainGetInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Get info from Database"/>
<TextView
android:id="@+id/txtGetMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabs3"
android:orientation="vertical"
>
<WebView
android:id="@+id/txtSpareGetInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Get info from Database"/>
<TextView
android:id="@+id/txtGetspare"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
类:
public class DetailsTabs extends Activity
{
TabSpec tspec;
FuelStoredInfo fuelInfo;
WebView fuelView,mainView,sparesView;
TextView tvFuel, tvMain, tvSpares;
WebSettings fuelSetting, mainSetting, spareSetting;
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.detailstabs);
fuelView = (WebView)findViewById(R.id.txtGetFuelInfo);
mainView = (WebView)findViewById(R.id.txtMainGetInfo);
sparesView = (WebView)findViewById(R.id.txtSpareGetInfo);
//tvFuel = (TextView)findViewById(R.id.totalFuelId);
//tvMain = (TextView)findViewById(R.id.totalmainId);
//tvSpares = (TextView)findViewById(R.id.totalspareId);
fuelInfo = new FuelStoredInfo(this);
fuelInfo.open();
TabHost th = (TabHost)findViewById(R.id.tabhost);
th.setup();
// Fuel Expense tab
tspec = th.newTabSpec("Tag 1");
tspec.setContent(R.id.tabs1);
tspec.setIndicator("Fuel"+"\n"+"Expense");
String Data = fuelInfo.getData();
double fuelTotal =fuelInfo.getTotalFuel();
fuelSetting = fuelView.getSettings();
fuelSetting.setDefaultFontSize(10);
//tvFuel.setText("Total fuel expense : Rs. "+ String.valueOf(fuelTotal));
fuelView.loadData(Data,"text/html",null);
th.addTab(tspec);
//Maintenance Expense tab
tspec = th.newTabSpec("Tag 2");
tspec.setContent(R.id.tabs2);
tspec.setIndicator("Maintenance"+"\n"+"Expense");
mainSetting = mainView.getSettings();
mainSetting.setDefaultFontSize(10);
String mainData = fuelInfo.getMainData();
double mainTotal =fuelInfo.getTotalMain();
tvMain.setText("Total maintenance expense : Rs. "+ String.valueOf(mainTotal));
mainView.loadData(mainData,"text/html",null);
th.addTab(tspec);
//Spares Expense tab
tspec = th.newTabSpec("Tag 3");
tspec.setContent(R.id.tabs3);
tspec.setIndicator("Spares"+"\n"+"Expense");
spareSetting = sparesView.getSettings();
spareSetting.setDefaultFontSize(10);
String sparesData= fuelInfo.getSpareData();
double spareTotal = fuelInfo.getTotalSpares();
tvSpares.setText("Total spares expense : Rs."+ String.valueOf(spareTotal));
sparesView.loadData(sparesData,"text/html",null);
th.addTab(tspec);
fuelInfo.close();
}
}