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

뷰페이저의 프래그넌트에 있는 버튼을 눌렀을때 이미지 가져오는법 질문있습니다.

0 추천

 

안녕하세요.

제가 현재 뷰페이저에 3개 정도의 이미지들을 저장을 해 놓았습니다.

그리고 뷰페이저의 프래그넌트에 뷰페이저에서 지정한 이미지 아래에 버튼들을 달아 놓았습니다.

 

여기서 제가 해결해야 하는 문제가 있는데 생각처럼 쉽게 되지 않아서 글을 올렸습니다.

뷰페이저의 각 이미지들을 눌렀을 경우에, 다른 액티비티에서 누른 이미지들이 뜨게 하는 방법은 알았는데,

이미지가 아닌, 각 뷰페이저의 프래그넌트에 속한 각 이미지의 아래에 있는 버튼들에 대해서 눌렀을 경우에

새로운 액티비티의 탭부분에, 이 사진이 뜨게 만들어야 하는데 이 방법을 도무지 모르겠습니다.

 

이해가 쉽게 아래의 사진을 첨부해 보았습니다.

아래의 사진에서, 보면 오른쪽으로 넘길때마다 사진들이 있고, 그 아래에 보면 "바로예매"라는 부분이 있습니다.

이 바로 예매 버튼을 눌렀을 경우에는 두번쨰와 같이, 누른 영화의 이미지가, 첫번째 탭의 배경으로

차지하게 되는데, 이 부분을 제코드에서 어떻게 변경을 시켜야될지 너무 막막합니다.

 

제가 현재 바로 아래의 사진까지 만들기는 했는데, 여기서 바로예매를 눌렀을 경우에 두번째 이미지처럼

탭의 첫번째 부분에, 이미지를 차지하게 하려면 어떻게 코드를 수정해야 할까요 ..ㅠ

아래의 소스를 한번 달아보았습니다.

8000자가 넘는 부분은 아래의 댓글에 이어서 붙여보았습니다.

ㅁ.jpg

 

ㄴ.jpg

 

< 뷰페이저의 자바부분 >

package ex.real_project;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.ArrayList;


public class HappyLife extends AppCompatActivity {

    ImageView v1;

    private SectionsPagerAdapter mSectionsPagerAdapter;

    public static ArrayList<Integer> at_thumnail = new ArrayList<>();           //
    public static ArrayList<String> at_title = new ArrayList<>();               //  
    public static ArrayList<String> at_ReservationPercent = new ArrayList<>();  // 

    private ViewPager mViewPager;

    static String  ARG_SECTION_NUMBER = "section_number";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setTitle("로그인화면 ");
        setContentView(R.layout.activity_happy_life);

        v1 = (ImageView) findViewById(R.id.Movie_Selection_LoginActivity);
        v1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getApplicationContext(),Login_Activity.class);
                startActivity(intent);
            }
        });


       

 

 

Kind카인드 (3,600 포인트) 님이 2016년 11월 3일 질문
// 여기같은 경우에는, 뷰페이저에 나타나는 사진임 ..
        at_thumnail.add(R.drawable.first_moive_image);
        at_thumnail.add(R.drawable.second_movie_image);
        at_thumnail.add(R.drawable.third_movie_image);
        at_thumnail.add(R.drawable.a4);
        at_thumnail.add(R.drawable.a5);

        at_title.add("1. 일번");
        at_title.add("2. 이번");
        at_title.add("3. 삼번");
        at_title.add("4. 사번");
        at_title.add("5. 오번");

        at_ReservationPercent.add(" 30.5%");
        at_ReservationPercent.add(" 30.5%");
        at_ReservationPercent.add(" 17.5%");
        at_ReservationPercent.add(" 24.5%");
        at_ReservationPercent.add(" 21.5%");

        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);
    }

   
    public static class PlaceholderFragment extends Fragment {

      
        public PlaceholderFragment() {
        }

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

            final int position = getArguments().getInt(ARG_SECTION_NUMBER);

            View rootView = inflater.inflate(R.layout.fragment_sub2, container, false);

            TextView title = (TextView) rootView.findViewById(R.id.title);
            title.setText(at_title.get(position));

            TextView Percent = (TextView) rootView.findViewById(R.id.Reservation_Percent);
            Percent.setText(at_ReservationPercent.get(position));

            ImageView thunmail = (ImageView) rootView.findViewById(R.id.thunmail);
            thunmail.setImageResource(at_thumnail.get(position));

            Button btn = (Button) rootView.findViewById(R.id.buy);

            // 이미지에 클릭 리너스를 단다.
            thunmail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                  
                    Intent intent = new Intent(getContext(),First_Movie.class);
                    intent.putExtra("pos",position);

                    startActivity(intent);
                }
            });


            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(getContext(),Date_and_Seat.class);
                    intent.putExtra("poss",position);
                    startActivity(intent);
                }
            });


            return rootView;
        }
    }


    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

    
        @Override
        public Fragment getItem(int position) {

            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, position);

   
            PlaceholderFragment fragment = new PlaceholderFragment();
            fragment.setArguments(args);

            return fragment;
        }

        @Override
        public int getCount() {
       
            return at_thumnail.size();
        }
    }
}







< 프래그넌트 부분 >


<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#262626"
    >

    <ImageView
        android:id="@+id/thunmail"
        android:layout_width="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_height="280dp" />

    <LinearLayout
        android:id="@+id/Side"
        android:orientation="horizontal"
        android:layout_width="160dp"
        android:layout_height="2dp"
        android:background="#ffffff"
        android:layout_below="@+id/title"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp">

    </LinearLayout>


    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:textColor="#ffffff"
        android:textAlignment="center"
        android:layout_below="@+id/thunmail"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="11dp" />

    <TextView
        android:id="@+id/Reservation_Percent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:textSize="20dp"
        android:textColor="#ffffff"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_below="@+id/Side"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:id="@+id/buy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:textColor="#00e6ff"
        android:background="@drawable/reservation_button"
        android:text="바로예매"
        android:textStyle="bold"
        android:layout_below="@+id/Reservation_Percent"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" />

</RelativeLayout>
< 탭호스트 부분 입니다 < 이미지의 2번쨰 >
<?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:background="@drawable/first_tab_image"
                                android:layout_height="330dp" />

                            <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>

답변 달기

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