CrimeId in details view not getting updated properly


#1

Hi ,
Awesome book … I like it very much.

My problem is that "If i click crime #1 or crime #2 or anyother crime in the listview " In the details view i am getting output only as “Crime #0

CrimeListFragment.java
public void onListItemClick(ListView l,View v,int position,long id ){

	Crime c =((CrimeAdapter)getListAdapter()).getItem(position);
	Intent i = new Intent(getActivity(),CrimeActivity.class);
	i.putExtra(CrimeFragment.EXTRA_CRIME_ID, c.getId());
	Toast.makeText(getActivity().getApplicationContext(), c.getTitle().toString(), Toast.LENGTH_SHORT).show(); -->[b]Here it shows the c.getTitle() being passed as the correct crime[/b] 
	startActivity(i);
	
}

CrimeFragment.java

public View onCreateView(LayoutInflater inflater,ViewGroup parent,Bundle savedInstanceState){

	View v = inflater.inflate(R.layout.fragment_crime, parent,false);
	mTitleField = (EditText)v.findViewById(R.id.crime_title);
	mTitleField.setText(mCrime.getTitle().toString());
	Toast.makeText(getActivity().getApplicationContext(), mCrime.getTitle().toString(), Toast.LENGTH_SHORT).show(); --> This one shows crime #0

#2

I guess the reason is that you did not get correct crime id in onCreate function in CrimeFragment.java like this:

[code] @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

    UUID crimeId = (UUID)getArguments().getSerializable(EXTRA_CRIME_ID);
    mCrime = CrimeLab.get(getActivity()).getCrime(crimeId);
}[/code]

but you don’t show you all code.