Android Open Source - CSCI567---Workspace My Fragment

From Project

Back to project page CSCI567---Workspace.


The source code is released under:

MIT License

If you think the Android project CSCI567---Workspace listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package csci567.FragmentExample;
/* ww w. ja v a 2 s . c  o  m*/
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class MyFragment extends Fragment implements OnClickListener{
  public static final String TAG = "myfrag";
  private GetFragNumber gfn;
  private Button changefrag;
  private TextView text;
  private int fragnumber = 0;
  private Fragmentmanageractivity fragmanager = null;
  static MyFragment newInstance() {
    MyFragment frag = new MyFragment();
    return frag;
  public interface GetFragNumber {
    public int getData();
  public void onAttach(Activity activity) {
      gfn = (GetFragNumber) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString()
          + " must implement GetFragNumber");
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
  View result = inflater.inflate(R.layout.my_fragment, container, false);
  fragnumber = gfn.getData();
  changefrag = (Button) result.findViewById(;

  text = (TextView) result.findViewById(;
    // Inflate the layout for this fragment
    return result; 

  public void onClick(View v) {
    fragmanager = (Fragmentmanageractivity) getActivity();
    int id = v.getId();
    if (id =={
      if(fragmanager != null)

Java Source Code List