
我只想要Firstname,Lastname,EmailID.
ModelLogin.class
public class ModalLogin implements Parcelable { @Serializedname("result") @Expose private String result; @Serializedname("customer-ID") @Expose private String customerID; @Serializedname("error_message") @Expose private String errorMessage; @Serializedname("APIname") @Expose private String APIname; @Serializedname("first_name") @Expose private String firstname; @Serializedname("last_name") @Expose private String lastname; @Serializedname("email") @Expose private String email; @Serializedname("quoteID") @Expose private Integer quoteID; @Serializedname("token") @Expose private String token; protected ModalLogin(Parcel in) { result = in.readString(); customerID = in.readString(); errorMessage = in.readString(); APIname = in.readString(); firstname = in.readString(); lastname = in.readString(); email = in.readString(); token = in.readString(); quoteID = in.readInt(); } public static final Creator<ModalLogin> CREATOR = new Creator<ModalLogin>() { @OverrIDe public ModalLogin createFromParcel(Parcel in) { return new ModalLogin(in); } @OverrIDe public ModalLogin[] newArray(int size) { return new ModalLogin[size]; } }; /** * * @return * The result */ public String getResult() { return result; } /** * * @param result * The result */ public voID setResult(String result) { this.result = result; } /** * * @return * The customerID */ public String getCustomerID() { return customerID; } /** * * @param customerID * The customer-ID */ public voID setCustomerID(String customerID) { this.customerID = customerID; } /** * * @return * The errorMessage */ public String getErrorMessage() { return errorMessage; } /** * * @param errorMessage * The error_message */ public voID setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } /** * * @return * The APIname */ public String getAPIname() { return APIname; } /** * * @param APIname * The APIname */ public voID setAPIname(String APIname) { this.APIname = APIname; } /** * * @return * The firstname */ public String getFirstname() { return firstname; } /** * * @param firstname * The first_name */ public voID setFirstname(String firstname) { this.firstname = firstname; } /** * * @return * The lastname */ public String getLastname() { return lastname; } /** * * @param lastname * The last_name */ public voID setLastname(String lastname) { this.lastname = lastname; } /** * * @return * The email */ public String getEmail() { return email; } /** * * @param email * The email */ public voID setEmail(String email) { this.email = email; } /** * * @return * The quoteID */ public String getQuoteID() { String ID = ""+quoteID; return ID; } /** * * @param quoteID * The quoteID */ public voID setQuoteID(String quoteID) { int ID = Integer.parseInt(quoteID); this.quoteID = ID; } /** * * @return * The token */ public String getToken() { return token; } /** * * @param token * The token */ public voID setToken(String token) { this.token = token; } @OverrIDe public int describeContents() { return 0; } @OverrIDe public voID writetoParcel(Parcel dest,int flags) { dest.writeString(result); dest.writeString(customerID); dest.writeString(errorMessage); dest.writeString(APIname); dest.writeString(firstname); dest.writeString(lastname); dest.writeString(email); dest.writeString(token); dest.writeInt(quoteID); }} 现在这是我的片段..
ProfileFragment.class
public class MyProfileFragment extends Fragment { private static final String ARG_ParaM1 = "param1"; private static final String ARG_ParaM2 = "param2"; private String mParam1; private String customerID; private VIEw mLoginFormVIEw,vIEw; private Progressbar mProgressVIEw; private button saveAddress,changepassword; private EditText fname,lname,emailID,mobileNo,oldPWD,newPWD; private OnFragmentInteractionListener mListener; private JsONObject JsonObject; private ModalLogin modelLogin; public MyProfileFragment() { // required empty public constructor } // Todo: Rename and change types and number of parameters public static MyProfileFragment newInstance(String param1,String param2) { MyProfileFragment fragment = new MyProfileFragment(); Bundle args = new Bundle(); args.putString(ARG_ParaM1,param1); args.putString(ARG_ParaM2,param2); fragment.setArguments(args); return fragment; } @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_ParaM1); customerID = getArguments().getString(ARG_ParaM2); } } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_my_profile,container,false); } @OverrIDe public voID onVIEwCreated(VIEw vIEw,Bundle savedInstanceState) { super.onVIEwCreated(vIEw,savedInstanceState); initVIEws(vIEw); } private voID initVIEws(VIEw v) { mLoginFormVIEw = (VIEw)v.findVIEwByID(R.ID.mainVIEw); mProgressVIEw =(Progressbar) v.findVIEwByID(R.ID.login_progress); vIEw = (VIEw) v.findVIEwByID(R.ID.mainV); saveAddress = (button)v.findVIEwByID(R.ID.button_save); changepassword = (button)v.findVIEwByID(R.ID.button_changePwd); fname = (EditText)v.findVIEwByID(R.ID.fname); lname =(EditText)v.findVIEwByID(R.ID.lname); emailID =(EditText)v.findVIEwByID(R.ID.email); mobileNo = (EditText)v.findVIEwByID(R.ID.telephone); changepassword.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { final Dialog paswordDialog = new Dialog(getActivity(),R.style.FullHeightDialog); paswordDialog.setContentVIEw(R.layout.dialog); paswordDialog.setCancelable(true); //Now that the dialog is set up,it's time to show it paswordDialog.show(); } }); } // 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 onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @OverrIDe public voID onDetach() { super.onDetach(); mListener = null; } public interface OnFragmentInteractionListener { // Todo: Update argument type and name voID onFragmentInteraction(Uri uri); } private voID showProgress(final boolean show) { mLoginFormVIEw.setVisibility(show ? VIEw.GONE : VIEw.VISIBLE); mProgressVIEw.setVisibility(show ? VIEw.VISIBLE : VIEw.GONE); }}解决方法 您可以在Fragment初始化时初始化相同的类实例: public class MyProfileFragment extends Fragment { private static final String ARG_ParaM1 = "param1"; private static final String ARG_ParaM2 = "param2"; // Declare instance here private ModelLogin mModelLogin; private String mParam1; private String customerID; private VIEw mLoginFormVIEw,String param2,ModelLogin mModelLogin) { MyProfileFragment fragment = new MyProfileFragment(); Bundle args = new Bundle(); args.putString(ARG_ParaM1,param2); fragment.setArguments(args); // Initialize instance here fragment.mModelLogin = mModelLogin; return fragment; } @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArguments().getString(ARG_ParaM1); customerID = getArguments().getString(ARG_ParaM2); // Now you can use wherever you want } } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,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 onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @OverrIDe public voID onDetach() { super.onDetach(); mListener = null; } public interface OnFragmentInteractionListener { // Todo: Update argument type and name voID onFragmentInteraction(Uri uri); } private voID showProgress(final boolean show) { mLoginFormVIEw.setVisibility(show ? VIEw.GONE : VIEw.VISIBLE); mProgressVIEw.setVisibility(show ? VIEw.VISIBLE : VIEw.GONE); }} 谢谢 :)
总结以上是内存溢出为你收集整理的android – 从模型类获取数据到片段全部内容,希望文章能够帮你解决android – 从模型类获取数据到片段所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)