Reputation: 27
I have try many different way such as change import.android.support.fragment
to import.support.v4.app.Fragment;
but it still showing the error cannot cast from Fragment to FragmentB can anyone help me out and tell me where is the error
package interfragmet.sim7n;
import android.app.Activity;
import android.app.FragmentManager;
import android.support.v4.app.Fragment;
import android.os.Bundle;
public class MainActivity extends Activity implements Communication{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void respond(String data) {
FragmentManager manager= getFragmentManager();
FragmentB f2= (FragmentB) manager.findFragmentById(R.id.fragmentB);
f2.changeText(data);
}
}
Upvotes: 1
Views: 375
Reputation: 10177
If you are using support v4 fragments then.
Imports:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
Upvotes: 1