2012-04-20 2 views
1

나는 다음과 같은 TabActivity 이제안드로이드 : 탭 선택에 따라 TabActivity에하여 ImageButton을 변경하는 방법

enter image description here

내가 탭 "AMT 사의를 정착"을 선택, 상단에하여 ImageButton 다른하여 ImageButton로 변경해야 한 멤버 탭을 선택하면 버튼이 표시되지 않습니다. ImageButton이 TabActivity에 있습니다. 탭 선택에 따라 동적으로 버튼 변경을 수행 할 수 있습니까?

public class TransactionTab extends TabActivity{ 
    String groupid=""; 
    TabHost tb; 
    TabSpec tab1,tab2,tab3; 
    Intent translist,settleamt,mems; 
    Context context = TransactionTab.this; 
    ImageButton v_createtrans; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.transactiontab); 

     Intent grpintent = getIntent(); 
     groupid = grpintent.getStringExtra("grpid"); 

     tb = (TabHost)findViewById(android.R.id.tabhost); 
     v_createtrans = (ImageButton)findViewById(R.id.x_createtrans); 

     tab1 = tb.newTabSpec("id1"); 
     tab2 = tb.newTabSpec("id2"); 
     tab3 = tb.newTabSpec("id3"); 

     mems = new Intent(context,MemberList.class); 
     mems.putExtra("grpid", groupid); 
     mems.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

     translist = new Intent(context,TransactionList.class); 
     translist.putExtra("grpid", groupid); 
     translist.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

     settleamt = new Intent(context,SettleAmount.class); 
     settleamt.putExtra("grpid", groupid); 
     settleamt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

     View layview = LayoutInflater.from(context).inflate(R.layout.tab_buttonbg, null); 
     Button bt = (Button) layview.findViewById(R.id.tabuton); 
     bt.setText("Members"); 
     tab1.setIndicator(layview); 
     tab1.setContent(mems); 

     layview = LayoutInflater.from(context).inflate(R.layout.tab_buttonbg, null); 
     Button bt1 = (Button) layview.findViewById(R.id.tabuton); 
     bt1.setText("Transactions"); 
     tab2.setIndicator(layview); 
     tab2.setContent(translist); 

     layview = LayoutInflater.from(context).inflate(R.layout.tab_buttonbg, null); 
     Button bt2 = (Button) layview.findViewById(R.id.tabuton); 
     bt2.setText("Settle Amt"); 
     tab3.setIndicator(layview); 
     tab3.setContent(settleamt); 

     tb.getTabWidget().setDividerDrawable(R.drawable.divider); 

     tb.addTab(tab1); 
     tb.addTab(tab2); 
     tb.addTab(tab3); 

     tb.setCurrentTab(1); 

     v_createtrans.setOnClickListener(new OnClickListener(){ 
      public void onClick(View v){ 
       Intent newtrans = new Intent(context,NewTransaction.class); 
       newtrans.putExtra("grpid", groupid); 
       startActivity(newtrans); 
      } 
     }); 

    } 

및 레이아웃 XML : 여기

내 TabActivity 얼마나 우리가 선택되어있는 탭을 알 수

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/grey_color"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:background="@color/app_header_color"> 

     <ImageButton 
      android:id="@+id/x_createtrans" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/addbtn" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="10dp" 
      android:background="@null"> 
     </ImageButton> 

    </RelativeLayout> 

    <TabHost 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@android:id/tabhost"> 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="#ffffff"> 
      </TabWidget> 

      <FrameLayout 
       android:layout_height="fill_parent" 
       android:layout_width="fill_parent" 
       android:id="@android:id/tabcontent"> 
      </FrameLayout> 

     </LinearLayout> 

    </TabHost> 

</LinearLayout> 

답변

0

시도는이 방법

TabHost.SetOnTabChangedListener(this){ 
protected void OnTabChanged() 
{ 

} 
} 
+0

를 사용하는/변경 되었습니까? 샘플 코드를 제공해 주시겠습니까? –

+0

참조 http://stackoverflow.com/questions/2243360/how-to-use-tabhost-ontabchangelistener-in-android –

+0

감사합니다. 그 위대한 일. 탭에서 TabActivity의 버튼에 액세스 할 수 있습니까? TabActivity에서 버튼을 클릭하면 탭 내부에서 수행해야하는 작업이 있습니다. –

관련 문제