<i id='Z4dv6'><tr id='Z4dv6'><dt id='Z4dv6'><q id='Z4dv6'><span id='Z4dv6'><b id='Z4dv6'><form id='Z4dv6'><ins id='Z4dv6'></ins><ul id='Z4dv6'></ul><sub id='Z4dv6'></sub></form><legend id='Z4dv6'></legend><bdo id='Z4dv6'><pre id='Z4dv6'><center id='Z4dv6'></center></pre></bdo></b><th id='Z4dv6'></th></span></q></dt></tr></i><div id='Z4dv6'><tfoot id='Z4dv6'></tfoot><dl id='Z4dv6'><fieldset id='Z4dv6'></fieldset></dl></div>

  1. <small id='Z4dv6'></small><noframes id='Z4dv6'>

    1. <tfoot id='Z4dv6'></tfoot>
      • <bdo id='Z4dv6'></bdo><ul id='Z4dv6'></ul>
      <legend id='Z4dv6'><style id='Z4dv6'><dir id='Z4dv6'><q id='Z4dv6'></q></dir></style></legend>

      无法解析方法'show(android.support.v4.app.FragmentManager, java

      Cannot resolve method #39;show(android.support.v4.app.FragmentManager, java.lang.String)(无法解析方法show(android.support.v4.app.FragmentManager, java.lang.String))

      <legend id='aFKjt'><style id='aFKjt'><dir id='aFKjt'><q id='aFKjt'></q></dir></style></legend>

        • <small id='aFKjt'></small><noframes id='aFKjt'>

        • <tfoot id='aFKjt'></tfoot>
          • <bdo id='aFKjt'></bdo><ul id='aFKjt'></ul>

              <tbody id='aFKjt'></tbody>
              <i id='aFKjt'><tr id='aFKjt'><dt id='aFKjt'><q id='aFKjt'><span id='aFKjt'><b id='aFKjt'><form id='aFKjt'><ins id='aFKjt'></ins><ul id='aFKjt'></ul><sub id='aFKjt'></sub></form><legend id='aFKjt'></legend><bdo id='aFKjt'><pre id='aFKjt'><center id='aFKjt'></center></pre></bdo></b><th id='aFKjt'></th></span></q></dt></tr></i><div id='aFKjt'><tfoot id='aFKjt'></tfoot><dl id='aFKjt'><fieldset id='aFKjt'></fieldset></dl></div>
                本文介绍了无法解析方法'show(android.support.v4.app.FragmentManager, java.lang.String)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                由于某种原因,当我尝试显示对话框时,我从 dialog.show(fm, DIALOG_DATE); 收到错误消息.说无法解析方法'show(android.support.v4.app.FragmentManager, java.lang.String)'

                For some reason when I try to show a Dialog I get an error from dialog.show(fm, DIALOG_DATE); saying Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)'

                为什么不能解析方法?

                mDateButton.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            FragmentManager fm = getActivity().getSupportFragmentManager();
                            DatePickerFragment dialog = new DatePickerFragment();
                            dialog.show(fm, DIALOG_DATE);
                        }
                    });
                

                这是我班的其余部分:

                package com.bignerdranch.android.criminalintent;
                import android.os.Bundle;
                import android.support.v4.app.Fragment;
                import android.support.v4.app.FragmentManager;
                import android.text.Editable; 
                import android.text.TextWatcher;
                import android.view.LayoutInflater;
                import android.view.View;
                import android.view.ViewGroup;
                import android.widget.CheckBox;
                import android.widget.Button;
                import android.widget.CompoundButton;
                import android.widget.CompoundButton.OnCheckedChangeListener;
                import android.widget.EditText;
                
                import java.util.UUID;
                
                
                public class CrimeFragment extends Fragment {
                //key for the extra
                public static final String EXTRA_CRIME_ID = "com.bignerdranch.android.criminalintent.crime_id";
                
                private static final String DIALOG_DATE = "date";
                
                //holds crime
                private Crime mCrime;
                
                //widgets
                private EditText mTitleField;
                private Button mDateButton;
                private CheckBox mSolvedCheckBox;
                
                //at start of build
                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    //get crime from crime class
                
                    /*Intents
                    *There are two ways a fragment can access data in its activity's intent:
                    * an easy direct shortcut
                    * or a complex flexible implementation
                    * First try out the shortcut
                    * in the shortcut, CrimeFragment will access CrimeActivity's intent directly
                     */
                
                    //retrieve the extra from CrimeActivity's intent and use it to fetch the Crime
                    //UUID crimeId = (UUID)getActivity().getIntent().getSerializableExtra   (EXTRA_CRIME_ID); //shortcut removed in chapter 10 and "should feel warm and fuzzy inside for maintaining CrimeFragments Independence"
                    //
                    UUID crimeId = (UUID)getArguments().getSerializable(EXTRA_CRIME_ID);
                    //CrimeLab.get() requires a context object, so CrimeFragment passes the CrimeActivity
                    mCrime = CrimeLab.get(getActivity()).getCrime(crimeId);
                
                }
                
                //Create the view and inflate the layout
                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                         Bundle savedInstanceState) {
                    // Inflate the layout for crime Fragment
                    //pass false because view will be added in the activitys code
                    View v = inflater.inflate(R.layout.fragment_crime, container, false);
                
                    //gets crime_title from fragment_crime.xml
                    mTitleField = (EditText)v.findViewById(R.id.crime_title);
                    mTitleField.setText(mCrime.getTitle());
                    mTitleField.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                            //not used
                        }
                
                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                              mCrime.setTitle(s.toString());
                        }
                
                        @Override
                        public void afterTextChanged(Editable s) {
                            //also not used
                        }
                    });
                
                
                    //find date button from fragment_crime
                    mDateButton = (Button)v.findViewById(R.id.crime_date);
                    //set mDateButton text to current date and time
                    mDateButton.setText(mCrime.getDate().toString());
                    //disable button for now...enabled in chapter 12
                   // mDateButton.setEnabled(false);
                
                
                    mDateButton.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            FragmentManager fm = getActivity().getSupportFragmentManager();
                            DatePickerFragment dialog = new DatePickerFragment();
                            dialog.show(fm, DIALOG_DATE);
                        }
                    });
                
                
                
                
                    //find solved checkbox from fragment_crime
                    mSolvedCheckBox = (CheckBox)v.findViewById(R.id.crime_solved);
                    mSolvedCheckBox.setChecked(mCrime.isSolved());
                    //user clicks solved check box
                    mSolvedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                            //set the crime's solved property
                            mCrime.setSolved(isChecked);
                        }
                    });
                    //returns the view
                    return v;
                }
                
                /*The downside to direct retrieval
                *can not encapsulate fragment
                * CrimeFragment is no longer a reusable building block because it expects that it will always be hosted by an activity whose intent defines extra named "EXTRA_CRIME_ID"
                * CrimeFragment cannot be used with just any activity
                *
                 */
                
                /*Fragment Arguments
                *A better solution is to stash the mCrimeId someplace that belongs to CrimeFragment rather than keeping it in CrimeActivity's personal space
                * this someplace can be an arguments bundle
                * Every fragment instance can have a Bundle object attached to it
                * bundle contains key value pairs that work just like the intent extras of an activity
                * Pg. 195
                 */
                
                /*attaching arguments to a fragment
                *Attaching args to frags must be done after the frag is created but before it is added to the activity
                * To hit this window use a static class called newInstance()
                * This method creates the fragment instance and bundles up and sets its arguments
                 */
                //for attaching arguments to a fragment
                public static CrimeFragment newInstance(UUID crimeId){
                    Bundle args = new Bundle();
                    args.putSerializable(EXTRA_CRIME_ID, crimeId);
                
                    CrimeFragment fragment = new CrimeFragment();
                    fragment.setArguments(args);
                
                    //pass UUID from extra
                    return fragment;
                }
                

                }

                推荐答案

                要解决这个问题,如果你使用的是 android.app.DialogFragment,那么使用 getFragmentManager():

                To solve this, if you are using android.app.DialogFragment, then use getFragmentManager():

                mDateButton.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            FragmentManager fm = getActivity().getFragmentManager();
                            DatePickerFragment dialog = new DatePickerFragment();
                            dialog.show(fm, DIALOG_DATE);
                        }
                    });
                

                使用 getSupportFragmentManager(),必须扩展自:android.support.v4.app.DialogFragment.

                检查您的导入:

                import android.support.v4.app.DialogFragment;
                

                这篇关于无法解析方法'show(android.support.v4.app.FragmentManager, java.lang.String)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

                  <tbody id='VlvS1'></tbody>

                1. <tfoot id='VlvS1'></tfoot>
                2. <i id='VlvS1'><tr id='VlvS1'><dt id='VlvS1'><q id='VlvS1'><span id='VlvS1'><b id='VlvS1'><form id='VlvS1'><ins id='VlvS1'></ins><ul id='VlvS1'></ul><sub id='VlvS1'></sub></form><legend id='VlvS1'></legend><bdo id='VlvS1'><pre id='VlvS1'><center id='VlvS1'></center></pre></bdo></b><th id='VlvS1'></th></span></q></dt></tr></i><div id='VlvS1'><tfoot id='VlvS1'></tfoot><dl id='VlvS1'><fieldset id='VlvS1'></fieldset></dl></div>

                  <small id='VlvS1'></small><noframes id='VlvS1'>

                  <legend id='VlvS1'><style id='VlvS1'><dir id='VlvS1'><q id='VlvS1'></q></dir></style></legend>
                    <bdo id='VlvS1'></bdo><ul id='VlvS1'></ul>