here we go again. I am writing an app using fragments. Stefan de Bruijn suggested this would be better than using the deprecated TabHost and he was right, Thank you Stefan.
I have finally got communication from one fragment to me Activity working thanks to help from other members (You know who you are, Thank you all).
I now have what hopefully is one last problem. My app has TextBox at the top that is part of the Activity, a permanent ListFragment on the left and FrameLayout on the right, to allow different Fragments to be displayed.
Is there any way of creating a generic "listener" if you like in the Activity that all the different Fragments can talk to?
To get one Fragment passing data I have used the following.
MainActivity
import com.example.fragger.CoreFragment.OnDataPass;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.EditText;
public class MainActivity extends Activity implements OnDataPass {
and Fragment Code:-
package com.example.fragger;
import android.app.Activity;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.view.View.OnClickListener;
public class CoreFragment extends Fragment{
int index;
Button Button1,Button2,Button3;
String Str,data;
OnDataPass dataPasser;
@Override
public void onAttach(Activity a) {
super.onAttach(a);
dataPasser = (OnDataPass) a;
}
public static CoreFragment newInstance(int index) {
CoreFragment coreFragment = new CoreFragment();
coreFragment.index = index;
return coreFragment;
}
public interface OnDataPass {
public void onDataPass(String data);
}
Which is all well and good until I show a different Fragment in my Frame (e.g. PlaceFragment). As the onDataPass is imported from CoreFragment and implemented, I cannot use it with anything else.
Is there any way around this?
Thanks all in advance. Gary