2017-01-25 1 views
0

누군가 나를 죽이는 것을 도와주세요! 나는 그것이 업데이트되지 않는 어떤 이유로 일하고있는 textview를 가지고있다. 텍스트는 탭이 공백으로 바뀌지 않습니다.Xamarin 탭 데이터 변경 안드로이드

참고 : 오류가 없거나 탭이 정상적으로 작동하며 텍스트가 업데이트되지 않습니다. 왜 도움을 요청하는지 알 수 없습니다 !! 사전에

감사

Main.cs :

using System; 
using Android.App; 
using Android.Content; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Android.OS; 

namespace App1 
{ 
    [Activity(Label = "ActionBar Tabs Example")] 
    public class Main : Activity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 

      // Set our view from the "main" layout resource 
      SetContentView(Resource.Layout.TabbedMenuPage); 

      //enable navigation mode to support tab layout 
      this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs; 

      //adding audio tab 
      AddTab("Audio", Resource.Drawable.Icon, new AudioFragment()); 

      //adding video tab 
      AddTab("Video", Resource.Drawable.Icon, new VideoFragment()); 
     } 

     /* 
     * This method is used to create and add dynamic tab view 
     * @Param, 
     * tabText: title to be displayed in tab 
     * iconResourceId: image/resource id 
     * fragment: fragment reference 
     * 
     */ 
     void AddTab(string tabText, int iconResourceId, Fragment fragment) 
     { 
      var tab = this.ActionBar.NewTab(); 
      tab.SetText(tabText); 
      tab.SetIcon(iconResourceId); 

      // must set event handler for replacing tabs tab 
      tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e) { 
       e.FragmentTransaction.Replace(Resource.Id.fragmentContainer, fragment); 
      }; 

      this.ActionBar.AddTab(tab); 
     } 


     class AudioFragment : Fragment 
     { 
      public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
      { 
       base.OnCreateView(inflater, container, savedInstanceState); 

       var view = inflater.Inflate(Resource.Layout.Tab, container, false); 
       var sampleTextView = view.FindViewById<TextView>(Resource.Id.textView); 
       sampleTextView.Text = "This is Audio Fragment Sample"; 
       return view; 
      } 
     } 

     class VideoFragment : Fragment 
     { 
      public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
      { 
       base.OnCreateView(inflater, container, savedInstanceState); 

       var view = inflater.Inflate(Resource.Layout.Tab, container, false); 
       var sampleTextView = view.FindViewById<TextView>(Resource.Id.textView); 
       sampleTextView.Text = "This is Video Fragment Sample"; 

       return view; 
      } 
     } 






    } 
} 

Tabaxml :

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/textView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:textStyle="bold" 
    android:textSize="16dp" 
    android:background="#ffe3e1e1" 
    android:textColor="#ff393939" /> 

TabbedMenu.axml :

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@+id/fragmentContainer" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      /> 
    </LinearLayout> 

답변

1

문제가 여기에 있습니다 :

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <FrameLayout 
      android:id="@+id/fragmentContainer" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      /> 
    </LinearLayout> 

FrameLayout의 높이가 0입니다. 그 안에있는 모든 콘텐츠가 숨겨져 있음을 의미합니다. layout_heightmatch_parent과 같은 다른 값으로 설정하십시오.

또한 사이드 노트 인 fill_parent은 더 이상 사용되지 않습니다. match_parent을 사용해야합니다.

+0

이 문제가 해결되었습니다. 정말 고맙습니다! – Jay

관련 문제