Why Can I Not Get My App To Successfully Send Data From One Fragment To Another?
I cannot get my app to successfully send data from one fragment to another. MainActivity.java which sets up my fragment tabs package myPackage; public class MainActivity extends A
Solution 1:
Warning:Not the best way but would do for now. Better solution would be to use Interface and use them as callback. See Passing data between two Fragments in a VIewPager (Android) (NullPointerException) and Passing data beetwen fragments in viewpager
Change PersonInformation like this
publicclassPersonInformationextendsFragment {
privateView rootView;
privateDatabaseHelper myDBHelper;
privateCursor informationCursor;
privateSimpleCursorAdapter mySimpleCursorAdapter;
privateTextView personIDDisplay;
@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
rootView = inflater.inflate(R.layout.person_information, container, false);
return rootView;
}
publicvoidinit(string personId)
{
myDBHelper = newDatabaseHelper(getActivity());
informationCursor = myDBHelper.getInformationCursor(personId);
String[] fromColumns = {"firstname", "lastname", "homephone", "homeaddress"};
int[] toViews = {R.id.firstname_textview, R.id.lastname_textview, R.id.homephone_textview, R.id.homeaddress_textview};
mySimpleCursorAdapter = newSimpleCursorAdapter(getActivity(), R.layout.information_layout, informationCursor, fromColumns, toViews, 0);
personIDDisplay = (TextView) rootView.findViewById(R.id.person_id_display);
personIDDisplay.setText("Person ID: " + personId);
ListView myListView = (ListView) rootView.findViewById(R.id.row_of_information);
myListView.setAdapter(mySimpleCursorAdapter);
myDBHelper.close();
}
}
Replace
PersonInformationpersonInformation=newPersonInformation();
BundlemyBundle=newBundle();
myBundle.putString("personID", personIDNumber);
personInformation.setArguments(myBundle);
getFragmentManager().beginTransaction().add(R.id.row_of_information, personInformation).commit();
with
Stringtag="android:switcher:" + R.id.pager + ":" + "1";
PersonInformationf= (PersonInformation) getSupportFragmentManager().findFragmentByTag(tag);
f.init(personIDNumber);
in onItemClick of Home fragment
Post a Comment for "Why Can I Not Get My App To Successfully Send Data From One Fragment To Another?"