Reputation: 2178
Been trying to implement Communicating with Other Fragments. There are errors during the selId.onIdSelected(pid.toString())
, and getting null pointer exception on this. I think I am not sure on what is the next thing to do. I am sure that when I click the current position has data but sending it to the other fragment is another thing.
public static class SectionFragment extends ListFragment {
OnSelectedIdListener selId;
public interface OnSelectedIdListener {
public void onIdSelected(String position);
}
public void IdSelected(String id) {
selId.onIdSelected(id);
}
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
selId = (OnSelectedIdListener) activity;
} catch (ClassCastException e) {
Log.d("error!: ",
String.format(e.toString(), "helow"));
}
}
....
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(pid!=null){
Log.d("if not null here", "pid? "+ pid.toString());
selId.onIdSelected(pid.toString());
}
else{Log.d("Null selected id", ""+position);}
}
}
Fragment B
public class PlayerFragment extends ListFragment implements
SectionFragment.OnSelectedIdListener{
@Override
public void onIdSelected(String position) {
setSelectedId(position);
}
}
Upvotes: 1
Views: 876
Reputation: 15774
OnSelectedListener
and idSelected
respectively.null
.Fragment
whereas in your code, you are casting the Activity
as the listener. Upvotes: 1