2014-06-10 4 views
0

가 나는 LinearLayout 국지적 인 이유에 ImageViewTextView 모두 ImageViewTextView을하는 포함하는 FragmentTabHost을 원하는 조각 탭 호스트에 표시하지, 내가 선택한 상태 모두 Views에 변경할 필요가있다 Tab Selected. 이것은 내 tab_view.xml안드로이드 화합물보기

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:orientation="vertical" > 
    <ImageView 
    android:id="@+id/img_tab" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_tab_alert" /> 
    <TextView 
    android:id="@+id/txt_tab" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:singleLine="true" 
    android:text="Alert" /> 
</LinearLayout> 

그리고 내 Compound View 클래스는 TabView

public class TabView extends FrameLayout { 

public ImageView imageView; 
public TextView textView; 

private String textValue; 
private int normalDrawableId, selectedDrawableId; 

public TabView(Context context, String textValue, int normalDrawableId, 
     int selectedDrawableId) { 
    super(context); 
    this.textValue = textValue; 
    this.normalDrawableId = normalDrawableId; 
    this.selectedDrawableId = selectedDrawableId; 

    View view = LayoutInflater.from(context).inflate(R.layout.tab_view, 
      this, false); 
    textView = (TextView) view.findViewById(R.id.txt_tab); 
    imageView = (ImageView) view.findViewById(R.id.img_tab); 
    textView.setText(textValue); 
    imageView.setImageResource(normalDrawableId); 
    } 
    } 

그리고 Activity 클래스에서, 내가 뭐하는 거지입니다 다음

public class MainActivity extends ActionBarActivity { 

private FragmentTabHost fragmentTabHost; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tab_layout); 
    fragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
    fragmentTabHost.setup(this, getSupportFragmentManager(), 
      R.id.realtabcontent); 

    Bundle params = new Bundle(); 

    TabSpec tabSpec = fragmentTabHost.newTabSpec("Alert").setIndicator(
      createTabView(fragmentTabHost.getContext(), "Alert", 
        R.drawable.ic_tab_alert, R.drawable.ic_tab_alert_red)); 
    fragmentTabHost.addTab(tabSpec, TabAlertFragment.class, params); 

    tabSpec = fragmentTabHost.newTabSpec("Community").setIndicator(
      createTabView(fragmentTabHost.getContext(), "Community", 
        R.drawable.ic_tab_community, 
        R.drawable.ic_tab_community_red)); 
    fragmentTabHost.addTab(tabSpec, TabCommunityFragment.class, params); 


} 

public TabView createTabView(Context context, String textValue, 
     int normalDrawableId, int selectedDrawableId) { 

    TabView tabView =new TabView(context,textValue,normalDrawableId,selectedDrawableId); 
    return tabView; 
} 
} 

그러나 나는 어떤을 볼 수없는거야 Tabs. 간단히 InflateLayoutActivity 클래스의 경우 Tab이 표시되지만 을 Compound Views과 함께 사용할 수 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

좋아 마침내 나는

View view = LayoutInflater.from(context).inflate(R.layout.tab_view, 
     this, false); 

를 해결이 문제를함으로써
View view = LayoutInflater.from(context).inflate(R.layout.tab_view, 
     this); 

을해야 내 코드에서 범인을 발견