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

Fragment안에 Graph를 출력하는데 이중으로 표시가 됩니다.

0 추천

프래그먼트 안에 버튼을 생성하여 버튼을 누르면 그래프가 출력되는 것을 적용하고 싶은데요. 

버튼을 생성해서 이벤트를 통해 그래프는 출력이 되는데 이중으로 출력되서 코드를 아무리봐도 어디가 잘못된 것인지 잘 모르겠네요!ㅠ 밑에 코드 첨부하겠습니다!

자바 코드 입니다.

package com.example.jungwh.fragmenttest.gui.ThirdTab;

import android.annotation.SuppressLint;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.support.v4.app.FragmentManager;
import android.widget.Button;

import com.example.jungwh.fragmenttest.R;

import static com.example.jungwh.fragmenttest.R.id.container;

/**
 * Created by jungwh on 2016-09-26.
 */

@SuppressLint("ValidFragment")
public class ThirdTabActivity extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_third_tab, container,false );
        Button btn0 = (Button) view.findViewById(R.id.btn0);
        Button btn1 = (Button) view.findViewById(R.id.btn1);
        Button btn2 = (Button) view.findViewById(R.id.btn2);

        btn0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectFrag(v);
                Log.i("STATE0","Log in SERVER BTN0");
            }
        });
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectFrag(v);
                Log.i("STATE1","Log in SERVER BTN1");
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectFrag(v);
                Log.i("STATE2","Log in SERVER BTN2");
            }
        });
        return view;
    }

    public void selectFrag(View view){
        Fragment fr;
        if(view == view.findViewById(R.id.btn2)){
            fr = new GraphInfoActivity2();
        }else if(view == view.findViewById(R.id.btn0)){
            fr = new GraphInfoActivity();
        }else {
            fr = new GraphInfoActivity1();
        }
        FragmentManager fm = getFragmentManager();
        FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_place, fr);
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        fragmentTransaction.addToBackStack(null);

        fragmentTransaction.commit();

    }
    }

xml 코드 입니다. 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:toos="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <Button
        android:id="@+id/btn0"
        android:background="@drawable/button_state"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="그래프0"/>
    <Button
        android:id="@+id/btn1"
        android:background="@drawable/button_state"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="그래프1"/>
        <Button
            android:id="@+id/btn2"
            android:background="@drawable/button_state"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="그래프2"/>
    </LinearLayout>
    <fragment
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/fragment_place"
        android:name="com.example.jungwh.fragmenttest.gui.ThirdTab.GraphInfoActivity1"
        toos:layout="@layout/fragment_third_tab"/>

</LinearLayout>

이걸 실행시키면 나오는 캡쳐 화면 입니다!

      

그래프가 두개가 나오면서 버튼을 클릭하면 밑에만 바뀌어요 ㅜㅠㅠ 답변 부탁드려요!

익명사용자 님이 2016년 10월 22일 질문

답변 달기

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