VibinReji Y
VibinReji Y

Reputation: 127

Tab inside android Activity

enter image description here

I need tab like above picture.if i choose Address it should show existing address tab.if i choose New Address it should show address form .but tabs should be in particular area of the activity.Is this possible in android?

Upvotes: 3

Views: 1049

Answers (3)

Silmood
Silmood

Reputation: 218

I think tabs use it like that would not be a good implementation in accordance to Android design gidelines. Instead, you could use two buttons that enable a fragment or view visibility. To manage the visibility behavior use the ViewStub class. Here is an example that show you how ViewStub works.

ViewStubExample

Upvotes: 0

A.R.
A.R.

Reputation: 2641

If you want to create your layout(View) in activity

1)Try use this xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<!--     ADD YOUR FIRST VIEW ie YOUR SELECT SERVICE DROP DOWN -->

<!--     ADD YOUR SECOND VIEW ie OF VISITING CHARGE 250 APPLICABLE -->


    <!-- LAYOUT FOR YOUR TAB -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/addressButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/addressActiveBtn"
            android:text="address" />

        <Button
            android:id="@+id/newAddressButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/addressDeActiveBtn"
            android:text="new address" />

    </LinearLayout>

    <!-- CREATE ADDRESS SCREEN LAYOUT AND INCLUDE HERE -->

    <include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/addressScreen"
        android:visibility="visible" />

    <!-- CREATE NEW ADDRESS SCREEN LAYOUT AND INCLUDE HERE -->

    <include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/newAddressScreen"
        android:visibility="gone" />

</LinearLayout>

2)You need to handle the Layout views(Address and New Address) by code.

ie you need to implement onClickListener on your tab buttons and handle
switching of layout views of Address and NewAddress

How:

addressButton.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        addressLinearLayout.setVisibility(View.VISIBLE);
        newAddressLinearLayout.setVisibility(View.GONE);
    }
});


newAddressButton.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

        addressLinearLayout.setVisibility(View.GONE);
        newAddressLinearLayout.setVisibility(View.VISIBLE);
    }
});

Hope this helps you somehow....

Upvotes: 2

MlleMei
MlleMei

Reputation: 146

I don't think it's possible to use Android's navigation tabs like that.

However, what I would do is create two buttons and two fragment. When clicking on the first button the fragment with the address would be shown, and when clicking the second button the form would be displayed.

You don't even have to use fragments, you could just hide the current address or the form visually with visibility.GONE, depending on which button is pressed, but I think using fragments is best practice.

Upvotes: 0

Related Questions