Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid -- Changing Tab Visibility from Inside Tab Activities
    primarykey
    data
    text
    <p>I'm currently attempting to change tabs from inside of other activities -- that much is straight forward. However, I'm having trouble when attempting to set the visibility of other tabs.</p> <p>Essentially, I have an application load to a tab (login page) and the other tabs are invisible until the user logs in.</p> <p>When the user logs in, I want to make the other tabs visible and the login tab invisible.</p> <p>If there is a simple way of doing this, please make me aware of it--I'm currently running around in circles:</p> <p>Code Snippets:</p> <p>In the TabHost's OnCreate:</p> <pre><code>..... tabHost.setCurrentTab(3); tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE); tabHost.getTabWidget().getChildAt(1).setVisibility(View.GONE); tabHost.getTabWidget().getChildAt(2).setVisibility(View.GONE); .... </code></pre> <p>The TabHost's Extra Methods:</p> <pre><code>public void switchTab(int tab){ tabHost.setCurrentTab(tab); } public void visibleTabs(){ tabHost.getTabWidget().getChildAt(0).setVisibility(View.VISIBLE); tabHost.getTabWidget().getChildAt(1).setVisibility(View.VISIBLE); tabHost.getTabWidget().getChildAt(2).setVisibility(View.VISIBLE); tabHost.getTabWidget().getChildAt(3).setVisibility(View.GONE); } public void invisibleTabs(){ tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE); tabHost.getTabWidget().getChildAt(1).setVisibility(View.GONE); tabHost.getTabWidget().getChildAt(2).setVisibility(View.GONE); } </code></pre> <p>The Tab Activity:</p> <pre><code>public class LoginActivity extends Activity { EditText txt_username; EditText txt_password; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); Button btn = (Button)this.findViewById(R.id.login_button); final EditText txt_username = (EditText) findViewById(R.id.txt_username); final EditText txt_password = (EditText) findViewById(R.id.txt_username); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String username = txt_username.getText().toString(); String password = txt_password.getText().toString(); switchTabInActivity(0); } }); } public void switchTabInActivity(long indexTabToSwitchTo){ waiter ParentActivity = (waiter) this.getParent(); ParentActivity.visibleTabs(); ParentActivity.switchTab(0); } } </code></pre> <p>LogCat is As Follows:</p> <pre><code>04-12 19:37:49.825: ERROR/AndroidRuntime(2744): FATAL EXCEPTION: main 04-12 19:37:49.825: ERROR/AndroidRuntime(2744): java.lang.NullPointerException 04-12 19:37:49.825: ERROR/AndroidRuntime(2744): at android.waiter.waiter.visibleTabs(waiter.java:130) 04-12 19:37:49.825: ERROR/AndroidRuntime(2744): at android.waiter.LoginActivity.switchTabInActivity(LoginActivity.java:56) 04-12 19:37:49.825: ERROR/AndroidRuntime(2744): at android.waiter.LoginActivity$1.onClick(LoginActivity.java:44) </code></pre> <p>Its obvious that the exception is coming from the invisible/visible settings.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload