2012-01-12 4 views
0

편집 : TextView의 상위 ScrollView 배경을 간단히 변경하여 아래 # 2를 해결했습니다.Android 탭 문제 - 프로그래밍 방식으로 내용 변경

나는 하루 종일 인터넷 검색을 해왔지만, 이것에 대한 답을 찾을 수없는 것 같습니다. 이것은 간단해야합니다.

내 활동에는 Tabbed 컨트롤 (TabHost, TabWidgets 등)으로 구성된 단편이 포함되어 있습니다. 각 탭에는 간단하고 스크롤하는 TextView가 있습니다. 사용자가 스크롤 할 수있는 다양한 텍스트 범주가있는 몇 가지 탭이 있어야합니다. 탭 등을 설정할 수 있었지만 해결할 수없는 두 가지 문제가 있습니다.

1) 탭의 TextView 내용을 프로그래밍 방식으로 (조각을 소유 한 활동에서) 변경하는 방법을 알 수 없습니다. 나는 내 호스트 액티비티 내에서 FragmentManager를 생성하고, 프래그먼트를 찾고, 프래그먼트를 내 프래그먼트 클래스로 캐스팅 한 다음, 텍스트를 변경해야하는 프래그먼트 클래스 내부에서 함수를 호출하려고 시도했습니다. 이 함수는 단순히 다음을 수행합니다.

TextView textView = (TextView)tabHost.getTabWidget().getChildAt(tabNumber).findViewById(R.id.dashboard_fragment_4_textView); 
    if(textView!=null) textView.setText(text); 

이것은 작동하지 않습니다. textView는 항상 null을 반환합니다.

2) 레이아웃 문제입니다. 각 탭의 TextView가 부모를 채우지 않습니다. 그것은 단지 텍스트 내용을 래핑합니다. 이것은 큰 문제는 아니지만 TextView에서 사용할 수있는 전체 화면 영역에 특정 배경색이 있어야합니다. 어쩌면 이걸 처리하는 더 좋은 방법이 있을까요 ??? TextView의 배경을 투명하게 처리 한 다음 TextView 뒤에 올바른 색상으로 무언가를 갖는 것? 나는 모른다 ... 나는 도달하고있다.

다음은 각 탭에 대한 XML 레이아웃입니다 : 어떤 제안에 대한

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/tabHost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 
<LinearLayout android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
    <TabWidget android:id="@android:id/tabs" 
       android:layout_height="match_parent" 
       android:layout_width="wrap_content" 
       android:gravity="left"     
       android:layout_weight="0" /> 
    <FrameLayout android:id="@android:id/tabcontent" 
       android:layout_height="match_parent" 
       android:layout_width="0dp" 
       android:layout_weight="1"> 

     <ScrollView 
      android:id="@+id/dashboard_fragment_4_scrollView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <TextView 
       android:id="@+id/dashboard_fragment_4_textView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@color/Linen" 
       android:textColor="@color/Black" 
       android:textSize="20dp" 
       android:text="TextView" /> 

     </ScrollView> 

    </FrameLayout> 
</LinearLayout> 

감사합니다!

브라이언 분명히

답변

0

, 그것은 tabs.getTabContentView() 대신 tabHost.getTabWidget()

+0

감사합니다 제프해야한다. 귀하의 의견은 저에게 부분적으로 도움이되었습니다. 나는 또한 내 XML 레이아웃을 변경해야했습니다. 나는 또한 각 탭 페이지마다 별도의 ScrollView/TextView를 갖기 위해 XML 파일을 변경해야했다 ... 이제는 생각했다. 이것을 처리하는 좀 더 우아한 방법이있을 수 있지만 그것은 나를 위해 일했습니다. 다시 한 번 감사드립니다! –

관련 문제