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
public class PersonInformation extends Fragment {
private View rootView;
private DatabaseHelper myDBHelper;
private Cursor informationCursor;
private SimpleCursorAdapter mySimpleCursorAdapter;
private TextView personIDDisplay;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
rootView = inflater.inflate(R.layout.person_information, container, false);
return rootView;
}
public void init(string personId)
{
myDBHelper = new DatabaseHelper(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 = new SimpleCursorAdapter(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
PersonInformation personInformation = new PersonInformation();
Bundle myBundle = new Bundle();
myBundle.putString("personID", personIDNumber);
personInformation.setArguments(myBundle);
getFragmentManager().beginTransaction().add(R.id.row_of_information, personInformation).commit();
with
String tag = "android:switcher:" + R.id.pager + ":" + "1";
PersonInformation f = (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?"