프래그먼트 안에 버튼을 생성하여 버튼을 누르면 그래프가 출력되는 것을 적용하고 싶은데요.
버튼을 생성해서 이벤트를 통해 그래프는 출력이 되는데 이중으로 출력되서 코드를 아무리봐도 어디가 잘못된 것인지 잘 모르겠네요!ㅠ 밑에 코드 첨부하겠습니다!
자바 코드 입니다.
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>
이걸 실행시키면 나오는 캡쳐 화면 입니다!

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