Проблема с Табами вфрагменте

Интерфейс, диалоги, темы, стили, меню
Ответить
solo
Сообщения: 1
Зарегистрирован: 11 май 2017, 14:49

Проблема с Табами вфрагменте

Сообщение solo » 11 май 2017, 15:02

Доброго времени суток, уже 8 дней бьюсь над проблемой, а спросить в целом-то и не у кого.. вот решил попробовать тут спросить помощи.
Суть в чем. Есть фрагмент, в котором располагается Tabhost(примеров реализации в интернетах почти не не нашлось, но в целом написал, другой вопрос на сколько верно). Когда вписываю то, что должно стать вкладками табов(самими кнопками) - табы не рисуются, а выводится просто как содержимый элемент layout-a. Я только начинаю учиться, сильно камнями не кидайте, пожалуйста.. Никак не могу заставить табы работать как табы..
большую часть писал как в уроке на startandroid, но там все красиво, а у меня шляпа.
код фрагмента и xml:

Код: Выделить всё

public class Fragment_search extends Fragment {

    public Fragment_search() {
        // Required empty public constructor


    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View mRoot = inflater.inflate(R.layout.fragment_search, container, false);

        TabHost tabhost = (TabHost) mRoot.findViewById(R.id.tabhost);

        tabhost.setup();

        TabHost.TabSpec tabSpec = tabhost.newTabSpec("tag1");
        tabSpec.setContent(R.id.tab1);
        tabSpec.setIndicator("Все");
        tabhost.addTab(tabSpec);

        tabSpec = tabhost.newTabSpec("tag2");
        tabSpec.setContent(R.id.tab2);
        tabSpec.setIndicator("Рядом");
        tabhost.addTab(tabSpec);

        tabSpec = tabhost.newTabSpec("tag3");
        tabSpec.setContent(R.id.tab3);
        tabSpec.setIndicator("Новые");
        tabhost.addTab(tabSpec);


        return inflater.inflate(R.layout.fragment_search, container, false);

Код: Выделить всё

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative_layout_for_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.solo.ver02.Fragment_search"
    android:background="#fafafa"
    android:orientation="vertical">
    <!-- TODO: Update blank fragment layout -->

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:gravity="center_horizontal"
        android:text="@string/anketa1000"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textSize="16sp" />

    <Button
        android:id="@+id/button"
        android:layout_width="160dp"
        android:layout_height="wrap_content"

        android:layout_gravity="center"
        android:layout_marginTop="18dp"
        android:background="@drawable/shape"
        android:text="@string/anketarise"
        android:textColor="@android:color/background_light" />

    <TabHost
        android:id="@+id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="1dp">

            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </FrameLayout>

            <TextView
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_weight="0.20"
                android:background="@color/colorPrimary"
                android:orientation="vertical"
                android:text="1111111111111111">

            </TextView>

            <TextView
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_weight="0.20"
                android:background="@color/colorPrimary"
                android:orientation="vertical"
                android:text="22222222222222">

            </TextView>

            <TextView
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_weight="0.20"
                android:background="@color/colorPrimary"
                android:orientation="vertical"
                android:text="333333333333333333">

            </TextView>
        </LinearLayout>
    </TabHost>

</LinearLayout>

Ответить