0

何が間違っているのかわかりません。リストビューとフラグメントを含むアクティビティがあります。リストビューからアイテムを押すと、フラグメントが別のフラグメントに置き換えられます。したがって、問題は、いくつかのビューをフラグメントに追加して別のフラグメントに置き換えると、最初のフラグメントに戻ると、ビューが追加されていないことです。いくつかのコードがあります:

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

        View addReport = inflater
                .inflate(R.layout.add_report, container, false);

        ListView listView = (ListView) addReport.findViewById(R.id.list);
        // listView.addHeaderView(padding);
        listView.setDivider(new GradientDrawable(Orientation.LEFT_RIGHT, colors));
        listView.setDividerHeight(1);

        remplirListOfReport();
        ReportAdaptor reportSchedule = new ReportAdaptor(getActivity(),
                R.layout.report_item_format, listOfReports);
        listView.setAdapter(reportSchedule);
        // Inflate the root layout
        myInflater = (LayoutInflater) addReport.getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);

        uploadFiles = (LinearLayout) addReport.findViewById(R.id.upload_layout);
        picture = (Button) addReport.findViewById(R.id.picture);
        video = (Button) addReport.findViewById(R.id.video);
        vocale = (Button) addReport.findViewById(R.id.vocal);
        report = (EditText) addReport.findViewById(R.id.report_text);

        picture.setOnClickListener(buttonOnClickListener);
        video.setOnClickListener(buttonOnClickListener);
        vocale.setOnClickListener(buttonOnClickListener);

        return addReport;
    }

Button.OnClickListener buttonOnClickListener = new Button.OnClickListener() {
        private String fullPathAudio = "";
    @Override
    public void onClick(View v) {
        if (v == picture) {
            if(null != getGPSCoordonnee(getActivity())){
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, MEDIA_TYPE_IMAGE);
            }
        } else if (v == video) {
            if(null != getGPSCoordonnee(getActivity())){
                 Intent intent1 = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
                 intent1.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set
                 //the video image quality to high
                 startActivityForResult(intent1, MEDIA_TYPE_VIDEO);
            }

        } else if (v == vocale) {
            if(null != getGPSCoordonnee(getActivity())){
                getOutputMediaFile(MEDIA_TYPE_AUDIO);
                fullPathAudio = URL_START_WITH + File.separator + AUDIO_NAME;

                vocale.setText("Vocal");
                View audioView = myInflater.inflate(R.layout.picture_format,
                        uploadFiles, false);

                description = (TextView) audioView
                        .findViewById(R.id.picture_text);
                imageView = (ImageView) audioView
                        .findViewById(R.id.picture_image);
                edit = (Button) audioView.findViewById(R.id.picture_edit);
                date = (TextView) audioView.findViewById(R.id.picture_date);

                date.setText(TIME);
                description.setText("Audio");

                imageView.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent2 = new Intent(getActivity(),
                                ShowVideo.class);
                        intent2.putExtra("videoName", fullPathAudio);
                        startActivity(intent2);
                    }
                });

                edit.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        editPictureNames(description);
                    }
                });

                uploadFiles.addView(audioView);

                Intent myIntent = new Intent(getActivity(),
                        AudioRecordingActivity.class);
                myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                myIntent.putExtra("path", fullPathAudio);
                getActivity().startActivity(myIntent);
            }
        } 
    }

};

私のアクティビティには、フラグメントを置き換えるメソッドがあります:

@Override
    public void addReport(long id) {
        LEADERBOARD_FRAG_TAG = "REPORT";
        int show = 0;
        fragment = getSupportFragmentManager().findFragmentByTag(LEADERBOARD_FRAG_TAG);
        if(null == fragment){
            fragment = new AddReportFragment();
            show = 0;
        }else
            show = 1;
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();

        transaction.replace(R.id.myFragment, fragment, LEADERBOARD_FRAG_TAG);
        transaction.addToBackStack(null);
        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        transaction.commit();
    }
4

1 に答える 1