For Challenge 2 how to use LinkedHashmap in OnBindViewHolder function in CrimeFragment.java


#1

I managed to convert mCrimes to LinkedHashList to increase performance of GetCrime but how do I use LinkedHashMap in on BindViewHolder in CrimeFragment.java .

Currently I am using the following code , It works but I would like to know a more efficient way . Thanks

public void onBindViewHolder(CrimeHolder holder, int position) {

        Collection<Crime> mArrayCrime=mCrimes.values();
        ArrayList<Crime> ArrayCrime=new ArrayList<Crime>();
        for( Crime c: mArrayCrime)
        {
            ArrayCrime.add(c);
        }


        Crime crime=ArrayCrime.get(position);
        holder.bind(crime);

    }

#2

Hello Nik1 you can converting LinkedHashMap to ArrayList in CrimeLab class

public List getCrimes() {
return new ArrayList<>(mCrimes.values());
}

and use it in onBindViewHolder in previous way