2012-03-23 6 views
0

주제에서와 마찬가지로 - 나는 이미 가지고있는 tabHost 위의 활동을 만들고 싶습니다.위의 활동 만들기 tabHost

탭 중 하나에 버튼이 있고 클릭 이벤트 후 tabHost를 오버레이 할 활동을 만들고 싶습니다.

또 다른 질문은 응용 프로그램 시작시 만드는 방법입니다 (때때로 숨겨져 야합니다).

답변

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); 
     } 
    }); 
,536을 시도 사용

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); 
    } 


} 

XML 시도

YourActivity는 시작하려는 활동입니다.

+0

나는 매우 일반적인 코드를 시도했지만 동일한 결과를 얻었습니다. nullExcepction : D/PhoneWindow (667) : 포커스가있는 뷰를 저장하지 못했습니다. [email protected] 이드는 없다. D/AndroidRuntime는 (667) : VM W/dalvikvm (667)를 종료하기 3 = threadid : 스레드 캐치되지 제외 종료 (그룹 = 0x4001b188) catch되지 핸들러 : 종료 메인 쓰레드 의한 캐치되지 않는 예외 java.lang.NullPointerException이에 android.widget.TabHost.dispatchWindowFocusChanged (TabHost.java:295) android.view.ViewGroup.dispatchWindowFocusChanged (ViewGroup.java:661)'어떤 생각입니까? –

+0

좋아, 해결 방법을 찾아 냈어. 나는 단순히 표시하려고하는 활동에서 잘못된 ID를 호출했다. :). 도와 주셔서 감사합니다. –

0

이 코드이이

<?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> 

이 mainfest이 하나

<?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 이벤트 이후에 특정 탭에서 다른 뷰가 표시되도록하고 싶습니다. –