title: How can I start activity inside frame?
body: <p>I'm trying to make a custom tabbar with scrolling tabbar items.</p>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="@drawable/bg"
      tools:context=".MainActivity" &gt;
  
      &lt;LinearLayout
          android:id="@+id/main_tabbar"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:layout_below="@+id/main_rlTopbar" &gt;
          &lt;FrameLayout
              android:id="@+id/main_tabcontent"
              android:layout_width="fill_parent"
              android:layout_height="0dp"
              android:layout_weight="1" /&gt;
          &lt;HorizontalScrollView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="0"
              android:background="@drawable/bottombar" &gt;
              &lt;LinearLayout
                  android:id="@+id/main_llTabs"
                  android:layout_width="wrap_content"
                  android:layout_height="fill_parent"
                  android:layout_gravity="center_vertical"
                  android:orientation="horizontal" &gt;
              &lt;/LinearLayout&gt;
          &lt;/HorizontalScrollView&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>mainactivity.java</p>
  
  <pre><code>...
          m_scrollTabbar = new HScrollTabbar(this, R.id.main_tabcontent, R.id.main_llTabs);
          m_scrollTabbar.addTab(null, 0, HomeActivity.class, true);
  ...
  </code></pre>
  
  <p>hscrolltabbar.java</p>
  
  <pre><code>public class HScrollTabbar {
      private int m_nTabContentId = -1;
      private int m_nScrollTabbarId = -1;
      private Activity m_activityParent = null;
      private ArrayList&lt;ButtonTabbarItem&gt; m_aryTabButton = new ArrayList&lt;ButtonTabbarItem&gt;();
  
      private int m_nSelectedIndex =  -1;
  
      public void addTab(String labelId, int drawableId, Class&lt;?&gt; c) {
          LinearLayout llTabs = (LinearLayout) m_activityParent.findViewById(m_nScrollTabbarId);
          ButtonTabbarItem item = new ButtonTabbarItem(m_activityParent, c, m_aryTabButton.size());
          llTabs.addView(item);
          m_aryTabButton.add(item);
          if (m_aryTabButton.size() == 1) {
              setSelectedIndex(0);
          }
          item.setOnSelectTabListener(onSelectTabListener);
      }
  
      private OnSelectTabListener onSelectTabListener = new OnSelectTabListener() {
          @Override
          public void onSelect(int nSelectedIndex) {
              setSelectedIndex(nSelectedIndex);
          }
      };
  
      public void setSelectedIndex(int nIndex) {
          if (m_nSelectedIndex == nIndex)
              return;
          ButtonTabbarItem item = null;
          if (m_nSelectedIndex &gt; -1) {
              item = m_aryTabButton.get(m_nSelectedIndex);
              item.setSelected(false);
          }
          m_nSelectedIndex = nIndex;
          item = m_aryTabButton.get(m_nSelectedIndex);
          item.setSelected(true);
  
              FrameLayout frame = (FrameLayout) m_activityParent.findViewById(m_nTabContentId);
              Intent intent = new Intent();
              intent.setClass(frame.getContext(), item.getClassTarget());
              frame.getContext().startActivity(intent);
      }
      public int getSelectedIndex() {
          return m_nSelectedIndex;
      }
  }
  </code></pre>
  
  <p>buttontabbaritem.java</p>
  
  <pre><code>public class ButtonTabbarItem extends FrameLayout {
      private static final int TAB_BTN_TAG = 100;
      private Class&lt;?&gt; m_classTarget;
      OnSelectTabListener m_listener = null;
  
      public ButtonTabbarItem(Context context, Class&lt;?&gt; classTarget, int nIndex) {
          super(context);
          LinearLayout layout = new LinearLayout(context);
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View view = inflater.inflate(R.layout.hscroll_tabbar_item, layout);
          addView(view);
  
          Button btn = (Button) view.findViewById(R.id.hscroll_tabbar_item_btn);
          btn.setOnClickListener(onClickTab);
          btn.setTag(TAB_BTN_TAG + nIndex);
  
          m_classTarget = classTarget;
      }
      public Class&lt;?&gt; getClassTarget() {
          return m_classTarget;
      }
      public void setClassTarget(Class&lt;?&gt; classTarget) {
          m_classTarget = classTarget;
      }
  
      public void setSelected(boolean bSelected) {
          if (bSelected) {
          } else {
          }
      }
  
      private OnClickListener onClickTab = new OnClickListener() {
          @Override
          public void onClick(View v) {
              if (m_listener != null)
                  m_listener.onSelect((Integer) v.getTag() - TAB_BTN_TAG);
          }
      };
  
      public interface OnSelectTabListener {
          public void onSelect(int nSelectedIndex);
      }
  
      public void setOnSelectTabListener(OnSelectTabListener listener) {
          m_listener = listener;
      }
  
  }
  
  
  
  FrameLayout frame = (FrameLayout) m_activityParent.findViewById(m_nTabContentId);
              Intent intent = new Intent();
              intent.setClass(frame.getContext(), item.getClassTarget());
              frame.getContext().startActivity(intent);
  </code></pre>
  
  <p>I'm trying to start activity inside frame, but it's not work.
  Please help me.</p>