2011-01-14 4 views
0

... 私はタブインターフェイスチュートリアルに従うと、このチュートリアルの結果は私のタブの下にコンテンツのない4つのタブ(テキスト)..ですアンドロイド:私は私のタブインターフェイスのためのビューを使用することを決定したCustomTabs

私は私は別のクラスからタブにコンテンツを設定するメソッドを作ることができます.. main.javaはビュー(タブ)を持つ私のメインファイルです。 Tab1.javaにはGoogleマップのナビゲーションコードがあります。事前に
ありがとう:私はあなたが私のコードを見ることができる方法のsetupTabを呼び出し、ここでは、タブ1

にナビゲーション機能を設定するにはどうすればよい

package CustomTabs; 
    import android.app.Activity; 
    import android.graphics.drawable.Drawable; 
    import android.os.Bundle; 
    import android.view.View; 
    import android.widget.TabHost; 
    import android.widget.TextView; 
    import android.widget.TabHost.TabContentFactory; 
    import android.widget.TabHost.TabSpec; 

    public class CustomTabs extends Activity { 

    private TabHost mTabHost; 

    private void setupTabHost() { 
     mTabHost = (TabHost) findViewById(android.R.id.tabhost); 
     mTabHost.setup(); 
    } 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     // construct the tabhost 
     setContentView(R.layout.main); 

     setupTabHost(); 

     setupTab(new TextView(this), "Tab 1", getResources().getDrawable(R.drawable.ic_tab_artists)); 
     setupTab(new TextView(this), "Tab 2", getResources().getDrawable(R.drawable.ic_tab_artists)); 
     setupTab(new TextView(this), "Tab 3", getResources().getDrawable(R.drawable.ic_tab_artists)); 
     setupTab(new TextView(this), "Tab 4", getResources().getDrawable(R.drawable.ic_tab_artists)); 
     { 
     final View v = mTabHost.getTabWidget().getChildAt(0); 
     v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector)); 
     TextView tv = (TextView) v.findViewById(android.R.id.title); 
     tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector)); 
     } 
     { 
     final View v = mTabHost.getTabWidget().getChildAt(1); 
     v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector)); 
     TextView tv = (TextView) v.findViewById(android.R.id.title); 
     tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector)); 
     } 
     { 
     final View v = mTabHost.getTabWidget().getChildAt(2); 
     v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector)); 
     TextView tv = (TextView) v.findViewById(android.R.id.title); 
     tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector)); 
     } 
     { 
     final View v = mTabHost.getTabWidget().getChildAt(3); 
     v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector)); 
     TextView tv = (TextView) v.findViewById(android.R.id.title); 
     tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector)); 
     } 

    } 

    private void setupTab(final View view, final String tag, Drawable icon) { 
     TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tag, icon).setContent(new TabContentFactory() { 
     public View createTabContent(String tag) {return view;} 
     }); 
     mTabHost.addTab(setContent); 

    } 
    } 

答えて

0

thisは何ですか?基本的には、インテントを設定して関連するタブに関連付けるだけです。

+0

いいえ私はそうは思わない..私は言ったことができるビューメソッドを作成することを望んでいた..例public void()setcontent View v {TextView textview = new TextView(this); textview.setText( "test")}しかし、私はこのメソッドを作成する方法を知らない。 – anddevelop

+0

申し訳ありませんが、あなたの質問は本当にありません。あなたは、タブのコンテンツを設定する方法を尋ねました。特定のクラスを実行するインテントを作成します。インテントintent = new Intent()。setClass(this、your_class.class); your_classでは、setTextまたは何をしたいのかを定義できます。 – springrolls

0

私がこの権利を理解している場合は、あなたのタブのコンテンツとしてアクティビティを追加したいので、あなたはsetupTabメソッドでインテントを追加する必要があります。例:

setupTab(new TextView(this), "title", getResources().getDrawable(R.drawable.icon), new Intent(this, yourclass.class)); 

これは、あなたのタブのインテントニーズを開始します。今、インテントはあなたのようなあなたのsetupTab方法にそれを追加する必要が見えるようにするためにはそう:これはあなたが探しているものではありません

private void setupTab(final View view, final String tag, Drawable drawable, Intent  intent) { 
    View tabview = createTabView(mTabHost.getContext(), tag, 0); 
    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent); 
    mTabHost.addTab(setContent); 

場合は、あなたの質問を修正再表示する必要があります。