Android Open Source - CSCI567---Workspace My Fragment






From Project

Back to project page CSCI567---Workspace.

License

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.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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();
  }
  
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    try{
      gfn = (GetFragNumber) activity;
    } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString()
          + " must implement GetFragNumber");
    }
  }
  
  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
  setRetainInstance(true);
  View result = inflater.inflate(R.layout.my_fragment, container, false);
  fragnumber = gfn.getData();
  changefrag = (Button) result.findViewById(R.id.button);
  changefrag.setOnClickListener(this);

  text = (TextView) result.findViewById(R.id.text);
  text.setText(Integer.toString(fragnumber));
    // Inflate the layout for this fragment
    return result; 
    }

  @Override
  public void onClick(View v) {
    fragmanager = (Fragmentmanageractivity) getActivity();
    int id = v.getId();
    if (id == R.id.button){
      if(fragmanager != null)
      fragmanager.addFragment();
    }
  }
}




Java Source Code List

com.example.linearlayoutexample.MainActivity.java
com.example.relativelayoutexample.MainActivity.java
csci567.FragmentExample.Fragmentmanageractivity.java
csci567.FragmentExample.MainActivity.java
csci567.FragmentExample.MyFragment.java
csci567.FragmentExample.MyStaticFragment.java
csci567.alarmexample.MainActivity.java
csci567.alarmexample.SampleAlarmReceiver.java
csci567.asynctaskexample.MainActivity.java
csci567.buttonexample.MainActivity.java
csci567.checkboxexample.MainActivity.java
csci567.doodleexample.MainActivity.java
csci567.doodleexample.SampleAlarmReceiver.java
csci567.doodleexample.SampleBootReceiver.java
csci567.doodleexample.SampleSchedulingService.java
csci567.eventreceiver.DataReceiver.java
csci567.eventreceiver.MainActivity.java
csci567.eventreceiver.RebootReceiver.java
csci567.helloworld.MainActivity.java
csci567.simpledbexample.DBHelper.java
csci567.simpledbexample.MainActivity.java
csci567.suggestionapp.MainActivity.java
csci567.writefile.MainActivity.java
org.ndeftools.boilerplate.AndroidNfcActivity.java
org.ndeftools.boilerplate.DefaultNfcBeamWriterActivity.java
org.ndeftools.boilerplate.DefaultNfcReaderActivity.java
org.ndeftools.boilerplate.DefaultNfcTagWriterActivity.java
org.ndeftools.boilerplate.NdefRecordAdapter.java
org.ndeftools.nfcdemo.TagViewer.java
org.ndeftools.nfcdemo.simulator.FakeTagsActivity.java
org.ndeftools.nfcdemo.simulator.MockNdefMessages.java