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

탭을 눌렀을때, 액티비티를 실행시키고 싶어요.

0 추천

 

안녕하세요.

탭을 눌렀을때, 새로운 액티비티를 실행시키고 싶은데(Location.class) TapHost에 있는 tap2 부분을 어떻게 구성을해야  눌렀을때 액티비티를 실행시켜야할지 잘 모르겠습니다.

그런데, tab2의 경우 tabhost에 하위에 있고 스크롤뷰의 하위에 있는거라.. 스크롤뷰로 만들어서 해보기도 했고 제가 할수있는 방법을 동원해서 해보긴 했는데.. 쉽지가 않네요 ㅠ

어떻게 바꾸어 주어야, 탭2부분을 눌렀을때 새로운 액티비티로 이동이 가능할까요??

소스가 조금 추가되는 부분은 아래에 추가시켜보겠습니다.

< 탭이 있는 부분의 xml 파일 >

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

                </TabWidget>

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

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

                   

                   

Kind카인드 (3,600 포인트) 님이 2016년 11월 5일 질문
<RelativeLayout
                        android:id="@+id/tableRow1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">


                        <ImageView
                            android:id="@+id/First_Tab_imageView"
                            android:layout_width="match_parent"
                            android:background="@drawable/first_tab_image"
                            android:layout_height="350dp" />

                        <Button
                            android:id="@+id/First_Tab_Button"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@id/First_Tab_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"   <!-- 이부분이 2번쨰 탭 같아요. -->
                    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>




< 탭이 있는 부분의 자바 파일 >
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.ScrollView;
import android.widget.TabHost;
import android.widget.Toast;

public class Date_and_Seat extends AppCompatActivity {

    ImageView Before_Date_and_Seat;
    Button btn;
    ImageView First_Tab_imageView;
    ScrollView v1;
    

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


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

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

                TabHost.TabSpec Tap2 = tab_host.newTabSpec("tab2");
                Tap2.setIndicator("2번");
                Tap2.setContent(R.id.tab2);
                tab_host.addTab(Tap2);

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

                tab_host.setCurrentTab(0);


        btn = (Button) findViewById(R.id.First_Tab_Button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(getApplicationContext(),Location.class);
                startActivity(it);

                
            }
        });

        
        v1 = (ScrollView) findViewById(R.id.scrollview);
        v1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 여기서 설정을 해줘야 하는데, 스크롤뷰로 받아서 하는건 아닌것 같고
                // 뭔가 다른 방법이 있는거 같은데 잘 모르곘어요.
            }
        });
        

        Before_Date_and_Seat = (ImageView) findViewById(R.id.Before_Date_and_Seat_Image);
        Before_Date_and_Seat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

         First_Tab_imageView = (ImageView) findViewById(R.id.First_Tab_imageView);
         // First_Tab_imageView.setImageResource();

    }
}

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...