2012-03-23 3 views
0

トピックに似ています - 既に持っているtabHostの上にアクティビティを作成したいと思います。上記のアクティビティを作成するtabHost

私はタブの中にボタンがあり、クリックイベントの後にtabHostをオーバーレイするアクティビティを作成したいと思います。

もう1つの質問は、アプリケーションの起動時に行う方法です(時には非表示にする必要があります)。

答えて

2

この

final (Button) yourButton = (Button)getViewById(R.id.your_button); 
    yourButton.setOnClickListener(new OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      Intent intent = new Intent(v.getContext(), YourActivity.class); 
      startActivityForResult(intent, 0); 
     } 
    }); 
を試してみてくださいを使用するXML

public class Test_tedActivity extends TabActivity { 
    /** Called when the activity is first created. */ 

    TabHost tabhost; 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Resources res = getResources(); 
     // TabHost tabhost = getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     intent = new Intent(this,Add.class); 
     spec = tabhost.newTabSpec("Add") 
       .setIndicator("add",res.getDrawable(R.drawable.plus)).setContent(intent); 
     tabhost.addTab(spec); 

     intent = new Intent(this,Show.class); 
     spec = tabhost.newTabSpec("Show") 
       .setIndicator("Show",res.getDrawable(R.drawable.information)).setContent(intent); 
     tabhost.addTab(spec); 

     intent = new Intent(this,Edit.class); 
     spec = tabhost.newTabSpec("Edit") 
       .setIndicator("Edit",res.getDrawable(R.drawable.edit)).setContent(intent); 
     tabhost.addTab(spec); 

     tabhost.setCurrentTab(2); 
    } 


} 

このコードを試してみてください

YourActivityは、開始するアクティビティです。

+0

私は既に非常に一般的なコードを試しましたが、同じ結果が得られましたnullExcepction:D/PhoneWindow(667):フォーカスされたビューはフォーカスがあるため保存できませんでした[email protected] idはありません。 D/AndroidRuntime(667):VM W/dalvikvm(667)をシャットダウンは:= 3スレッドID:キャッチされない例外により のjava.lang.NullPointerExceptionに出るメインスレッド:スレッドが捕捉されない例外(グループ= 0x4001b188) キャッチされないハンドラに出ます android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295) android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661) '任意のアイデア? –

+0

私はそれを修正する方法を見つけました...私は単に私が表示しようとした活動から間違ったIDを呼び出しました:)。手伝ってくれてありがとう。 –

0

あなたは、これがmainfest

<?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="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     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" > 
     </FrameLayout> 
    </LinearLayout> 

</TabHost> 

この1

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.ketan.test" android:versionCode="1" 
    android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".Test_tedActivity" android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".Add" android:label="Add"></activity> 
     <activity android:name=".Edit" android:label="Edit"></activity> 
     <activity android:name=".Show" android:label="Show"></activity> 
    </application> 
</manifest> 
+0

そのコード私は既にtabHostを提示しなければなりません...私はonClickイベント後に特定のタブからトリガされる別のビューを提示したいと思います。 –

関連する問題