2012-04-13 76 views
1

我有搜索,似乎可以找到任何接近我有問題的東西,所以我想我會問。 我有一個儀表盤佈局帶TabHost的Android儀表板佈局

enter image description here

這是所有工作正常

我想要做的就是它的工作如下圖所示(我有Tabhost定義,但我不得不設置的類延長TabActivity打破了動作條導航)

enter image description here

的選項卡切換正確的,但它不會允許我使用任何按鈕操作欄,它不拉的信息正確地像它應該是

enter image description here

以上正常工作。所以我想我的問題是我如何正確地將TabHost添加到我的類中,並讓它擴展或實現儀表板代碼?我試圖擴展TabActivity實現儀表板沒有運氣。

這裏是我的代碼迄今

Dashboard.java

package com.ondrovic.bbym; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.Configuration; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.LinearLayout; 
import android.widget.TextView; 

public abstract class Dashboard extends Activity { 
public static final boolean usePrettyGoodSolution = false; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

public void onDestroy() { 
    super.onDestroy(); 
} 

public void onPause() { 
    super.onPause(); 
} 

public void onRestart() { 
    super.onRestart(); 
} 

public void onResume() { 
    super.onResume(); 
} 

public void onStart() { 
    super.onStart(); 
} 

public void onStop() { 
    super.onStop(); 
} 

public void onClickHome(View v) { 
    goHome(this); 
} 

public void onClickUpdate(View v) { 
    //startActivity(new Intent(getApplicationContext(), Update.class)); 
} 

public void onClickAbout(View v) { 
    //startActivity(new Intent(getApplicationContext(), About.class)); 
} 

public void goHome(Context context) { 
    final Intent intent = new Intent(context, Home.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    context.startActivity(intent); 
} 

@Override 
public void setContentView(int layoutID) { 
    if (!usePrettyGoodSolution) { 
     super.setContentView(layoutID); 
     return; 
    } 

    Configuration c = getResources().getConfiguration(); 
    int size = c.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; 
    boolean isLarge = (size == Configuration.SCREENLAYOUT_SIZE_LARGE); 
    boolean isXLarge = (size == Configuration.SCREENLAYOUT_SIZE_XLARGE); 
    boolean addFrame = isLarge || isXLarge; 

    // if (isLarge) System.out.println ("Large screen"); 
    // if (isXLarge) System.out.println ("XLarge screen"); 

    int finalLayoutId = addFrame ? R.layout.large : layoutID; 
    super.setContentView(finalLayoutId); 

    if (addFrame) { 
     LinearLayout frameView = (LinearLayout) findViewById(R.id.frame); 
     if (frameView != null) { 

      // If the frameView is there, inflate the layout given as an 
      // argument. 
      // Attach it as a child to the frameView. 
      LayoutInflater li = ((Activity) this).getLayoutInflater(); 
      View childView = li.inflate(layoutID, null); 
      if (childView != null) { 
       LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
         ViewGroup.LayoutParams.MATCH_PARENT, 
         ViewGroup.LayoutParams.MATCH_PARENT, 1.0F); 
       frameView.addView(childView, lp); 
       // childView.setBackgroundResource (R.color.background1); 
      } 

     } 
    } 
} 

public void setTitleFromActivityLabel(int textViewID) { 
    TextView tv = (TextView) findViewById(textViewID); 
    if (tv !=null) { 
     tv.setText(getTitle()); 
    } 
} 

} 

Individual.java

package com.ondrovic.bbym; 

import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 

public class Individual extends TabActivity { 
public void onCreate(Bundle savedSate) { 
    super.onCreate(savedSate); 
    setContentView(R.layout.individual); 

    TabHost tabHost = getTabHost(); 
    TabSpec attspec = tabHost.newTabSpec("ATT"); 
    attspec.setIndicator("AT&T", getResources().getDrawable(R.drawable.icons_att_tab)); 
    Intent attIntent = new Intent(this, Individual_ATT.class); 
    attspec.setContent(attIntent); 

    TabSpec sprspec = tabHost.newTabSpec("SPRINT"); 
    sprspec.setIndicator("SPRINT", getResources().getDrawable(R.drawable.icons_sprint_tab)); 
    Intent sprIntent = new Intent(this, Individual_SPRINT.class); 
    sprspec.setContent(sprIntent); 

    TabSpec vzwspec = tabHost.newTabSpec("VERIZON"); 
    vzwspec.setIndicator("VERIZON", getResources().getDrawable(R.drawable.icons_verizon_tab)); 
    Intent vzwIntent = new Intent(this, Individual_VERIZON.class); 
    vzwspec.setContent(vzwIntent); 

    tabHost.addTab(attspec); 

    tabHost.addTab(sprspec); 

    tabHost.addTab(vzwspec); 
} 
} 

這裏是我的individual.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:background="@color/background1" 
android:orientation="vertical" > 

<include layout="@layout/title_bar" /> 
<include layout="@layout/tabs" /> 
</LinearLayout> 

如果有任何其他代碼t帽子需要發佈請讓我知道,並感謝您的幫助

+0

請記住,您無需擴展TabActivity即可在Android中使用選項卡。看看iosched應​​用程序的源代碼,他們做了類似於你想要的東西。 – Cristian 2012-04-13 16:16:24

+0

我已經瀏覽了iosched,但它現在超過了我的水平,但感謝您的信息 – ondrovic 2012-04-13 17:36:39

回答

0

所以我通過下面的計算出來。即使有可能在這裏更好的辦法是什麼我有

Individual.java

package com.ondrovic.bbym; 

import android.app.LocalActivityManager; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 

public class Individual extends Dashboard { 
    TabHost mTabs; 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.individual); 
    setTitleFromActivityLabel(R.id.title_text); 

    mTabs = (TabHost) findViewById(android.R.id.tabhost); 
    LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false); 
    mLocalActivityManager.dispatchCreate(savedInstanceState); 
    mTabs.setup(mLocalActivityManager); 

    TabSpec attspec = mTabs.newTabSpec("ATT"); 
    attspec.setIndicator("AT&T", getResources().getDrawable(R.drawable.icons_att_tab)); 
    Intent attIntent = new Intent(this, Individual_ATT.class); 
    attspec.setContent(attIntent); 

    TabSpec sprintspec = mTabs.newTabSpec("SPRINT"); 
    sprintspec.setIndicator("SPRINT", getResources().getDrawable(R.drawable.icons_sprint_tab)); 
    Intent sprintIntent = new Intent(this, Individual_SPRINT.class); 
    sprintspec.setContent(sprintIntent); 

    TabSpec verizonspec = mTabs.newTabSpec("VERIZON"); 
    verizonspec.setIndicator("VERIZON", getResources().getDrawable(R.drawable.icons_verizon_tab)); 
    Intent verizonIntent = new Intent(this, Individual_ATT.class); 
    verizonspec.setContent(verizonIntent); 

    mTabs.addTab(attspec); 
    mTabs.addTab(sprintspec); 
    mTabs.addTab(verizonspec); 
} 
} 

這裏的結果一切正常:-)

enter image description here