Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way you are doing your 'TAB' implementation is totally wrong. First of all, you should use <code>FrameLayout</code> as parent view to add/replace your <code>Fragments</code>. Second thing is that the logic in <code>onTabSelected</code> should be changed. Here is an example which is the proper way to use Tab Navigation in ActionBar. </p> <p>First create your main.xml, where your Fragments will be added/attached :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <p>Second you can create your tabs and add <code>TabListener</code> to them :</p> <pre><code>mMyActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab mFirstTab = mMyActionBar.newTab(); mFirstTab.setText("First Tab"); mFirstTab.setTabListener(this); mMyActionBar.addTab(mFirstTab); ActionBar.Tab mSecondTab = mMyActionBar.newTab(); mSecondTab.setText("Second Tab"); mSecondTab.setTabListener(this); mMyActionBar.addTab(mSecondTab); ActionBar.Tab mThirdTab = mMyActionBar.newTab(); mThirdTab.setText("Third Tab"); mThirdTab.setTabListener(this); mMyActionBar.addTab(mThirdTab); </code></pre> <p>and create your TabListener like this :</p> <pre><code>public void onTabSelected(Tab tab, FragmentTransaction ft) { // Check if the fragment is already initialized if (mFirstTab == null) { // If not, instantiate and add it to the activity mFirstTab = Fragment.instantiate(mActivity, mClass.getName()); ft.add(android.R.id.content, mFirstTab, mTag); } else { // If it exists, simply attach it in order to show it ft.attach(mFirstTab); } } public void onTabUnselected(Tab tab, FragmentTransaction ft) { if (mFirstTab != null) { // Detach the fragment, because another one is being attached ft.detach(mFirstTab); } } public void onTabReselected(Tab tab, FragmentTransaction ft) { // User selected the already selected tab. Usually do nothing. } </code></pre> <p>And about <code>NullPointerException</code> in your code, as I can see your <code>EditText</code> : <code>textBox = (EditText)findViewById(R.id.editText1);</code> which you are trying to use in your <code>MainActivity</code> is declared in your third's tab layout. This <code>EditText</code> should be declared and used in your <code>FragMent3</code>, not in <code>MainActivity</code> .</p> <p>Hope this answer help you!</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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