2017-07-20 19 views
0

2番目のフラグメントを呼び出すと、2つのフラグメントが表示されますが、最初のフラグメントのボタンは表示され、機能します。Android:古いフラグメントから見えるフラグメント

私は多くの多くの方法を試みたが、

This 1は私にこのエラーを与えた動作しませんでした:

java.lang.IllegalArgumentException: No view found for id 0x7f0e0004 (*.test:id/customId) for fragment SecondFragment{adef947 #0 id=0x7f0e0004}

This

java.lang.IllegalArgumentException: No view found for id 0x7f0e00ae (sy.aya.ayaisp.test:id/gatesViewpager) for fragment SecondSFragment{adef947 #0 id=0x7f0e00ae}

を次のように私のコードは次のとおりです。

FirstFragment.java

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

     View myView = inflater.inflate(R.layout.first_fragment, container, false); 
     Button FBtn = (Button) myView.findViewById(R.id.Fbutton); 
FBtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Bundle bundle = new Bundle(); 
       bundle.putString("second", "f button"); 
       SecondFragment secondFragment = new secondFragment(); 
       secondFragment.setArguments(bundle); 

       FragmentTransaction ft = getChildFragmentManager().beginTransaction(); 
       ft.setCustomAnimations(R.anim.slide_in_up, R.anim.slide_in_up); 
       ft.replace(R.id.s_con, secondFragment).addToBackStack("back").commit(); 
      } 
     }); 

SecondFrag.java

 @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     String bundleString = this.getArguments().getString("second"); 
     View view = inflater.inflate(R.layout.s_rv, container, false); 
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.s_recyclerview); 
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); 
if (bundleString == "agents button") { 
    recyclerView.setAdapter(new SecondAdapter(getContext())); 
} 
} 

first_fragment.xml

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/s_con" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <Button 
    android:id="@+id/Fbutton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="secondFragment"/> 
    </android.support.constraint.ConstraintLayout> 

s_rv.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <sy.aya.ayaisp.ExpandableRecyclerView 
     android:id="@+id/s_recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="5dp" 
     android:clipToPadding="false" 
     android:scrollbars="vertical" /> 
</FrameLayout> 

XMLのルート要素における第2のフラグメントレイアウト "s_rv" であなたの助け

答えて

1

いただきありがとうございます、いくつかbackgroundclickable="true"を追加し、 focusable="true"

最初のフラグメントレイアウトでは、LinearLayoutにボタンをラップします。 2日後、私は同じ問題に直面していました。それはその後、それが解決されました。

+0

他のコンテナにビューを配置するだけで動作します。なぜ説明できますか? – Zacktamondo

+0

私は同じ問題に直面しており、これを行うことで解決しました。 私はそれがいくつかの階層のためだと思う、ボタンはフラグメントよりも優先されます。 私はちょうど推測しています;) – Shivam

+0

あなたの助けをありがとう – Zacktamondo

0

最初のフラグメントでは、ボタンのidは "pos_agents_button"ですが、findViewByIdでは "R.id.Fbutton"を探しています。

Button FBtn = (Button) myView.findViewById(R.id.pos_agents_button); 

、すべてが正常に動作する必要がありますへ

変更

Button FBtn = (Button) myView.findViewById(R.id.Fbutton); 

+0

申し訳ありません私の悪いが、ここでコードを置いている間にいくつかのリソースのIDを変更するのを忘れて、私はそれをアプリケーションとしてそれを編集しました ありがとう – Zacktamondo

関連する問題