마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

버튼을 눌렀을때, 탭쪽으로 이동시켜보고 싶어요.

0 추천

 

안녕하세요.

아래의 사진에서 보면, 이미지 아래의 버튼을 눌렀을때 Tab2쪽으로 입력부분이 가지게 하고싶은데 어떻게 해

야할지 잘 모르겠습니다. < 클릭이 된 형태로도 괜찮습니다. 어떻게 보면 같은 말일수도 있겠네요>

아래의 xml과 자바의 소스를 한번 적어보겠습니다. 길이가 좀 넘는것은 아래의 댓글부분에 추가로

달아보겠습니다.. ㅠ ㅠ

 

 

< 자바 부분>

package ex.real_project;

import android.content.Intent;
import android.graphics.drawable.Icon;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.Toast;

public class Date_and_Seat extends AppCompatActivity {

    ImageView Before_Date_and_Seat;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_date_and__seat);


                TabHost tab_host = (TabHost) findViewById(R.id.tabhost);
                tab_host.setup();

                TabHost.TabSpec Tap1 = tab_host.newTabSpec("tab1");
                Tap1.setIndicator("영화");
                Tap1.setContent(R.id.tab1);
                tab_host.addTab(Tap1);

                TabHost.TabSpec Tap2 = tab_host.newTabSpec("tab2");
                Tap2.setIndicator("영화관 선택");
                Tap2.setContent(R.id.tab2);
                tab_host.addTab(Tap2);

                TabHost.TabSpec Tap3 = tab_host.newTabSpec("tab2");
                Tap3.setIndicator("날짜");
                Tap3.setContent(R.id.tab3);
                tab_host.addTab(Tap3);

                tab_host.setCurrentTab(0);

                tab_host.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                                               Intent it = new Intent(getApplicationContext(),Location.class);
                        startActivity(it);
                    }
                });

            /*
        btn = (Button) findViewById(R.id.First_Tab_Button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Tap1.setIndicator("선택");
            }
        });
            */
    }
}
Kind카인드 (3,600 포인트) 님이 2016년 11월 3일 질문
[xml 부분의 입력내용 입니다]


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_date_and__seat"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="ex.real_project.Date_and_Seat">

    <RelativeLayout
        android:id="@+id/Date_and_Seat_Toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/Before_Date_and_Seat_Image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="3dp"
        android:layout_marginLeft="3dp"
        android:background="@drawable/before_image" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="영화별 예매"
        android:textSize="30dp"
        android:textStyle="bold"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true" />

    </RelativeLayout>


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

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

                    <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"

                    >

                     </TabWidget>

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

                    <ScrollView
                        android:id="@+id/tab1"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent" >

                        <RelativeLayout
                            android:id="@+id/tableRow1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent">


                            <ImageView
                                android:id="@+id/imageView"
                                android:layout_width="match_parent"
                                android:scaleType="fitEnd"
                                android:background="@drawable/first_tab_image"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:layout_height="300dp" />

                            <Button
                                android:id="@+id/First_Tab_Button"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@id/imageView"
                                android:layout_marginTop="20dp"
                                android:text="영화관 선택"
                                android:layout_centerHorizontal="true"
                                android:textAlignment="center"
                                android:textColor="#9000ff"
                                android:background="@drawable/white_round_button"
                                />


                        </RelativeLayout>

                    </ScrollView>

                    <ScrollView
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <Button
                                android:id="@+id/button2"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="test2"
                                android:textAppearance="?android:attr/textAppearanceMedium" />
                    </ScrollView>


                    <ScrollView
                        android:id="@+id/tab3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <TextView
                            android:id="@+id/textView3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="test3"
                            android:textAppearance="?android:attr/textAppearanceMedium" />
                    </ScrollView>

                </FrameLayout>
            </LinearLayout>
    </TabHost>

</LinearLayout>

1개의 답변

0 추천
 
채택된 답변
탭을 이동하면 되는건가요~? ViewPager를 사용해보셔도 될것 같습니다

저도 비슷한 UI를 가진 앱을 개발중인데 ViewPager를 사용하고 있습니다
핸디 (1,840 포인트) 님이 2016년 11월 3일 답변
Kind카인드님이 2016년 11월 3일 채택됨
위의 사진에서 확인 버튼을 눌렀을때, Tab2으로 이동을 시켜보고 싶어요.

제가 탭호스트를 쓰는 이유는 각 탭 아래의 화면들을 계속 구성해줘야해서
탭 호스트를 쓰고 있어요. 저번에 어떤분이 뷰페이저로도 만드는걸 추천해주셨는데 탭호스트가 더 낫다고 여러분들이 하셔서 탭호스트로 만들었어요. ㅠ
해결했습니다. 감사합니다.
...