Android Studio default generates fragment

Source: Internet
Author: User

Package com.edaixi.fragment;

Import Android.content.Context;
Import Android.net.Uri;
Import Android.os.Bundle;
Import android.support.v4.app.Fragment;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.TextView;
Import COM.EDAIXI.ACTIVITY.R;

/**
* A Simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link Blankfragment.onfragmentinteractionlistener} interface
* To handle interaction events.
* Use the {@link Blankfragment#newinstance} factory method to
* Create an instance of this fragment.
*
*/
public class Blankfragment extends Fragment {
Todo:rename parameter arguments, choose names that match
The fragment initialization parameters, e.g. Arg_item_number
private static final String arg_param1 = "param1";
private static final String arg_param2 = "param2";

Todo:rename and change types of parameters
Private String mParam1;
Private String mParam2;

Private Onfragmentinteractionlistener Mlistener;

/**
* Use this factory method to create a new instance of
* This fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment Blankfragment.
*/
Todo:rename and change types and number of parameters
public static Blankfragment newinstance (String param1, string param2) {
Blankfragment fragment = new Blankfragment ();
Bundle args = new bundle ();
Args.putstring (arg_param1, param1);
Args.putstring (ARG_PARAM2, param2);
Fragment.setarguments (args);
return fragment;
}
Public Blankfragment () {
Required empty Public constructor
}

@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
if (getarguments () = null) {
mParam1 = Getarguments (). getString (ARG_PARAM1);
MPARAM2 = Getarguments (). getString (ARG_PARAM2);
}
}

@Override
Public View Oncreateview (layoutinflater inflater, ViewGroup container,
Bundle savedinstancestate) {
TextView TextView = new TextView (getactivity ());
Textview.settext (r.string.hello_blank_fragment);
return textView;
}

Todo:rename method, update argument and hook method into UI event
public void onbuttonpressed (Uri uri) {
if (Mlistener! = null) {
Mlistener.onfragmentinteraction (URI);
}
}

@Override
public void Onattach (context context) {
Super.onattach (context);
If (context instanceof Onfragmentinteractionlistener) {
Mlistener = (onfragmentinteractionlistener) context;
} else {
throw new RuntimeException (Context.tostring ()
+ "must implement Onfragmentinteractionlistener");
}
}

@Override
public void Ondetach () {
Super.ondetach ();
Mlistener = null;
}

/**
* This interface must is implemented by activities it contain this
* Fragment to allow a interaction in this fragment to be communicated
* To the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "Http://developer.android.com/training/basics/fragments/communicating.html"
* >communicating with other fragments</a> for more information.
*/
Public interface Onfragmentinteractionlistener {
Todo:update argument type and name
void Onfragmentinteraction (URI uri);
}
}

Android Studio default generates fragment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.