WebViewFragment webView is null after doing a FragmentTransaction

前端 未结 4 1855
故里飘歌
故里飘歌 2020-12-24 15:18

I currently have my application set up with a ListFragment on the left and a DetailsFragment on the right (similar to the layout on the tablet belo

4条回答
  •  温柔的废话
    2020-12-24 15:55

    Fragments can only be replaced if they were initiallized in Java, not XML. I think so, I had the same problem and it solved it. Change your XML to this:

    
    
    
      
          
      
      
      
    
    
    

    and then in Java, your onCreate method:

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.my_container, new DealDetailsFragment());
    transaction.commit();
    

    or even better create whole method to just deal with Transactions.

    Now Transaction from your question should work. :)

提交回复
热议问题