我正在開發一個應用程序Android 4
。我的應用程序中有三個tabs
。我的要求是,我想在開始時只顯示第一個標籤,點擊標籤1中的某個按鈕後,我想要顯示第二個標籤,點擊按鈕後,第三個標籤將會顯示。如何在Android中隱藏ActionBar中的單個Tab 4
因爲Android 3
中的標籤,沒有setVisibility
方法,請告訴我如何在我的情況下show/hide
particular tab
。
任何幫助將不勝感激。
謝謝。
UPDATE:按鈕的的onClick,我加入這個代碼:
ActionBar actionbar = getActivity().getActionBar();
ActionBar.Tab Tab2 = actionbar.newTab().setText("XYZ");
ActionBar.Tab Tab3 = actionbar.newTab().setText("PQR");
Fragment Tab2Fragment = new BFragment();
Fragment Tab3Fragment = new CFragment();
Tab2.setTabListener(new MyTabsListener(Tab2Fragment));
Tab3.setTabListener(new MyTabsListener(Tab3Fragment));
actionbar.addTab(Tab2);
actionbar.addTab(Tab3);
但還是它不工作..
UPDATE:現在我可以看到兩個選項卡來了,但我我得到NPE:
06-08 20:57:58.101: E/AndroidRuntime(17070): java.lang.NullPointerException
06-08 20:57:58.101: E/AndroidRuntime(17070): at de.arvidg.exampleactionbartabs.AFragment.onActivityCreated(AFragment.java:116)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:847)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.app.BackStackRecord.run(BackStackRecord.java:622)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:426)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.os.Handler.handleCallback(Handler.java:605)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.os.Looper.loop(Looper.java:137)
06-08 20:57:58.101: E/AndroidRuntime(17070): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-08 20:57:58.101: E/AndroidRuntime(17070): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 20:57:58.101: E/AndroidRuntime(17070): at java.lang.reflect.Method.invoke(Method.java:511)
06-08 20:57:58.101: E/AndroidRuntime(17070): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-08 20:57:58.101: E/AndroidRuntime(17070): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-08 20:57:58.101: E/AndroidRuntime(17070): at dalvik.system.NativeStart.main(Native Method)
這是我的onCreateView和onActivityCreated在AFragment是:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.afragment, container, false);
}
/* (non-Javadoc)
* @see android.app.Fragment#onActivityCreated(android.os.Bundle)
*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
appContext = AFragment.this;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Toast.makeText(getActivity(), "NO Bluetooth Available", Toast.LENGTH_LONG);
getActivity().finish();
return;
}
final Button connectBtn = (Button) getActivity().findViewById(R.id.connect_btn);
connectBtn.setClickable(true); // NPE is occurring here...
}
ActionBar.Tab Tab2 = actionBar.newTab(); ,然後調用Tab2.setText(「XYZ」)和actionbar.addTab(Tab2); – CSmith