Saturday 15 June 2013

java - Passing Data From an Activity to a Fragment in Android -


I am very new to Java and Android programming. I am trying to explain that one activity is the variable How to pass a bundle that uses the setrent view in an XML file which is linked to a class that extends the list. Actually, I want to be able to access data from the first activity through the piece that has reached into other activity. I am trying to do research to take advantage of it so far, please forgive me if the answer is already present.

I have an activity called log, which does the following:

  intent = new intent (this, ListActivity.class); Bundle varBundle = new bundle (); VarBundle.putString ("companyKey", companyKey); VarBundle.putString ("techID", techID); VarBundle.putString ("user id", userID); VarBundle.putString ("STARTDATE", STARTDATE); Intent.putExtras (varBundle); StartActivity;   

In ListActivity.java, I still have this:

  Activity activity of the public category list {is spread to the public string company; Public string tech ed; Public string user id; Public string startup; @ Override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); Bundle Wars = Friendly (). GetExtras (); CompanyKey = vars.getString ("company"); Tech = vars.getString ("techID"); UserID = vars.getString ("userID"); StartDate = vars.getString ("Start"); SetContentView (R.layout.fragmentlist); } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Enhancing Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Flood (R.menu.list, menu); Back true; }}   

I have set the content view to fragmentlist.xml:

     

Fragmentlist.xml is attached to the order list.java. This is where I want the data of the bundle in ListActivity.java to be able to enter the list.

  Public Class OrderList Extends LiftFragment {// This is where I want to access the categories included in the list. Java public order list () {super (); // Todo Auto-Generated Constructor Stub} @SuppressWarnings ({}) @ Override Crate on Public Zero (Bundle Saved InstantState) {// Todo Auto-Generated Method Stub Super. Connet (Saved Instantstate); }}   

Is this possible? Again I apologize if this is a fraudulent question but I have not yet received the answer.

Thank you in advance.

You can call (from within your piece)

  String company's name = (GetActivity (ListActivity)) CompanyKey; String technique id = (getActivity (list activation)). TechId; Letter userId = (ListActivity) getActivity ()). UserId; String StartDate = (ListActivity) getActivity ()). StartDate;    

No comments:

Post a Comment