我的Android应用由三个片段:A,B和C.它们被加载到MainActivity布局中定义的两个容器中.
当应用程序启动时,它会显示在left_container中加载的fragmentA和在right_container中加载的fragmentC.
如果按在按钮fragmentA,一个FragmentTransaction改变FragmentC通过FragmentB.
一切都好.但是当我尝试使用加载的fragmentB的引用时出现问题 findFragmentByTag(),因为它返回null.我已经使用了方法替换,FragmentTransaction并且我已经完成了它commit(),但是没有办法调用FragmentB方法.我的代码:
MainActivity.java:
public class MainActivity extends Activity{
static String fragmentTag = "FRAGMENTB_TAG";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Adds the left container's fragment
getFragmentManager().beginTransaction().add(R.id.left_container, new FragmentA()).commit(); //Adds the fragment A to the left container
//Adds the right container's fragment
getFragmentManager().beginTransaction().add(R.id.right_container, new FragmentC()).commit(); //Adds the Fragment C …Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有Swift和Xcode 6的iOS应用程序.我想要做的是使用AVAudioEngine播放音频文件,直到这一切都好.但是我怎么能不停地播放它,我的意思是,当它结束播放它再次开始?
这是我的代码:
/*==================== CONFIGURATES THE AVAUDIOENGINE ===========*/
audioEngine.reset() //Resets any previous configuration on AudioEngine
let audioPlayerNode = AVAudioPlayerNode() //The node that will play the actual sound
audioEngine.attachNode(audioPlayerNode) //Attachs the node to the audioengine
audioEngine.connect(audioPlayerNode, to: audioEngine.outputNode, format: nil) //Connects the applause playback node to the sound output
audioPlayerNode.scheduleFile(applause.applauseFile, atTime: nil, completionHandler: nil)
audioEngine.startAndReturnError(nil)
audioPlayerNode.play() //Plays the sound
Run Code Online (Sandbox Code Playgroud)
在我说我应该使用AVAudioPlayer之前,我不能因为以后我将不得不使用一些效果并同时播放三个音频文件,也是反复的.