2012-03-14 2 views
0

이 코드를 사용하고 있습니다.Android에서 탭 호스트의 모든 탭에 공통 버튼을 추가하는 방법은 무엇입니까?

private ViewGroup createTabbarView() { 

     bookedZone = "None"; 
     bookedStand = "None"; 

     tabHost = new TabHost(this, null); 
     tabHost.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

     Button btn = new Button(this); 
     btn.setText("Emergency"); 
     tabHost.addView(btn, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 

     tabWidget = new TabWidget(this); 
     tabWidget.setId(android.R.id.tabs); 
     tabHost.addView(tabWidget, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 

     FrameLayout frameLayout = new FrameLayout(this); 
     frameLayout.setId(android.R.id.tabcontent); 
     frameLayout.setPadding(0, 100, 0, 0); 
     tabHost.addView(frameLayout, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // WRAP_CONTENT 

     tabHost.setOnTabChangedListener(new OnTabChangeListener() { 

      public void onTabChanged(final String tabId) { 
       if (tabId.equalsIgnoreCase("TripList") 
         && (AVL_Service.pref.getBoolean("BluetoothMeter", false) || AVL_Service.pref.getBoolean("VivotechDevice", false) || AVL_Service.pref.getBoolean(
           "BlueBambooDevice", false))) { 
        if (mBluetoothAdapter == null) 
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
        final Context tempContext = getBaseContext(); 
        if (mBluetoothAdapter == null) { 
         // Device does not support Bluetooth 
         Log.d(getClass().getSimpleName(), "Bluetooth not supported."); 
         Toast.makeText(tempContext, "Bluetooth not supported!", Toast.LENGTH_LONG).show(); 
        } else { 
         if (!mBluetoothAdapter.isEnabled()) { 
          Log.d(getClass().getSimpleName(), "Bluetooth not enabled."); 
          Toast.makeText(tempContext, "Bluetooth not enabled, trying to enable", Toast.LENGTH_LONG).show(); 
          Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
          startActivityForResult(enableBtIntent, Constants.REQUEST_ENABLE_BT); 
          // tabHost.getTabWidget().getChildAt(ZoneIndex).requestFocusFromTouch(); 
         } else { 

          Message lmsg = new Message(); 
          lmsg.obj = null; 
          lmsg.what = MsgType.TabberClick; 
          msgHandler.sendMessageDelayed(lmsg, 1000); 

         }// if bluetooth enabled 
        }// if bluetooth not supported 
       }// if Bluetooth connection required 
       else if (tabId.equalsIgnoreCase("Status")) { 
        setMeterStatus(); 
       } 
      }// onTabChanged 
     }); 

     tabHost.setup(); 

     // Status Tab 
     TabSpec tabSpec = tabHost.newTabSpec("Status"); 
     tabSpec.setIndicator("Status", getResources().getDrawable(R.drawable.status)); 
     tabSpec.setContent(new TabContentFactory() { 
      @Override 
      public View createTabContent(String arg0) { 

       return createStatusView(); 
      } 
     }); 
     tabHost.addTab(tabSpec); 

     // Zones Tab 
     tabSpec = tabHost.newTabSpec("Zones"); 
     tabSpec.setIndicator("Zones", getResources().getDrawable(R.drawable.zones)); 
     tabSpec.setContent(new TabContentFactory() { 

      @Override 
      public View createTabContent(String arg0) { 

       return createZoneView(); 
      } 
     }); 
     tabHost.addTab(tabSpec); 

     // Bids Tab 
     bidTab = tabHost.newTabSpec("Bids"); 
     bidTab.setIndicator("Bids", getResources().getDrawable(R.drawable.icon + bidCount)); 
     bidTab.setContent(new TabContentFactory() { 

      @Override 
      public View createTabContent(String arg0) { 

       return createBidsView(); 
      } 
     }); 
     tabHost.addTab(bidTab); 

     // TripList Tab 
     tabSpec = tabHost.newTabSpec("TripList"); 
     tabSpec.setIndicator("TripList", getResources().getDrawable(R.drawable.triplist)); 
     tabSpec.setContent(new TabContentFactory() { 

      @Override 
      public View createTabContent(String arg0) { 

       return createManifestView(); 
      } 
     }); 
     tabHost.addTab(tabSpec); 

     return tabHost; 
    } 

는 // Tabber보기

는하지만이 버튼을 Tabber보기의 탭을 숨 깁니다. Tabber 뷰 위에이 단추를 추가하려면 추가하고 싶습니다. Plz 도와주세요 .. 나는 큰 곤경에 처해있다. 감사합니다.

답변

1

기본적으로 어떤 탭을 선택했는지에 관계없이 TabWidget 탭 위에있는 버튼 (또는 버튼)을 원하십니까?

그냥

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    ... > 
    <LinearLayout 
     android:orientation="vertical" 
     ... > 
     <LinearLayout 
      android:orientation="horizontal" 
      ... > 
      <Button 
       ... /> 
     </LinearLayout> 
     <TabWidget 
      android:id="@android:id/tabs" 
      ... /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      ... > 
      ... 
     </FrameLayout> 
    </LinearLayout> 
</TabHost 
+0

나는 이것을 시도했지만 동적으로 작동하지 않았다 ...이 (의사 코드)과 비슷한으로 레이아웃 파일을 변경합니다. xml.Regards를 사용하지 않아서 동적으로 처리하는 방법을 알려줄 수 있습니까? –

+0

XML을 사용하지 않는 이유는 무엇입니까? 탭필 내용을 동적으로 생성해야하는 경우에도 기본보기에 XML 템플릿을 사용할 수없고 단순히 탭 내용을 생성 할 이유가 없습니다. 내가 너 자신을 위해 많은 일을하고있는 것 같아. – Squonk

관련 문제