I want to pass same value from adapter to fragment and I send it in next way:
Fragment fr = new Fragment
fr.deleteMothod(Position);
when I call above code , it is creating new instance of Fragment therefore I am not accessing values of fragment. How to use old instance of fragment.
You can modify the constructor of your fragment like so:
public static DetailsFragment newInstance(String selection, String[] selectionArgs) {
DetailsFragment detailsFragment = new DetailsFragment();
Bundle args = new Bundle();
args.putString("selection", selection);
args.putStringArray("selectionArgs", selectionArgs);
detailsFragment.setArguments(args);
return detailsFragment;
}
However there is a much better way of doing this, if you use an interface.
You should retrieve your fragment from the Fragment manager by id or tag, then call the method on it. These are the official docs http://developer.android.com/training/basics/fragments/communicating.html#Deliver
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.