Nie ma newInstance...
Właśnie nie do końca wiem jak to przekazać.
public class DescFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.desc_row, container, false);
}
}
próbowałem coś takiego:
public class DescFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.desc_row, container, false);
long id = getArguments().getLong("id");
return view;
}
}
ale jest nullpointexception...
Dodam w DescActivity.java w onCreate:
Intent intent = getIntent();
intent.getLongExtra("id", -1);
ale jak to potem przekazać do DescFragment?
Mogę dodać w DescActivity jakąś publiczną metodę np.
public Long getID() { return id; }
a w DescFragment w onCreate dodać coś takiego:
DescActivity activity = (DescActivity) getActivity();
long id = activity.getID();
tylko czy to jest poprawne rozwiązanie?
A co gdybym activity_desc.xml chciał dodać kilka takich fragmentów i np. kilka buttonów? Jak to wtedy zaimplementować?