shows the handcuffs image upto crime 10 after that when i scroll none of the itemviews has handcuffs image even though isSolved is checked in.
package app.com.abhi.android.criminalintent;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.List;
import static android.R.attr.start;
import static android.R.string.no;
/**
- Created by ABHI on 3/5/2017.
*/
public class CrimeListFragment extends Fragment {
private RecyclerView mRecyclerview;
CrimeAdapter mAdapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_crime_list,container,false);
mRecyclerview = (RecyclerView) view.findViewById(R.id.crime_recycler_view);
mRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
updateUI();
return view;
}
private void updateUI() {
CrimeLab crimeLab = CrimeLab.get(getActivity());
List<Crime> crimes = crimeLab.getCrimes();
// if(mAdapter==null) {
mAdapter = new CrimeAdapter(crimes);
mRecyclerview.setAdapter(mAdapter);
// }
//else
// mAdapter.notifyDataSetChanged();
}
private class CrimeHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private TextView mTextview;
private TextView mDateTextView;
private ImageView mimage;
Crime mcrime;
public CrimeHolder(View itemView){
super(itemView);
mTextview = (TextView) itemView.findViewById(R.id.title_item_view);
mDateTextView = (TextView) itemView.findViewById(R.id.date_item_view);
mimage = (ImageView) itemView.findViewById(R.id.is_solved_image);
itemView.setOnClickListener(this);
}
private void bind(Crime crime){
mcrime = crime;
String date=String.format(" %1$tB %1$td , %1$tY ",crime.getMdate());
mTextview.setText(crime.getmTitle());
mDateTextView.setText(date);
if (!crime.ismSolved()) mimage.setVisibility(View.GONE);
}
@Override
public void onClick(View v) {
// Toast.makeText(getActivity(),"clicked an itemView",Toast.LENGTH_SHORT).show();
Intent intent = CrimeActivity.newIntent(getActivity(),mcrime.getmId());
startActivity(intent);
}
}
private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder>{
private List<Crime> mCrimes;
public CrimeAdapter(List<Crime> crimes){
mCrimes = crimes;
}
@Override
public CrimeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater;
inflater = LayoutInflater.from(getActivity());
return new CrimeHolder(inflater.inflate(R.layout.list_item_crime,parent,false));
}
@Override
public void onBindViewHolder(CrimeHolder holder, int position) {
Crime crime = mCrimes.get(position);
holder.bind(crime);
}
@Override
public int getItemCount() {
return mCrimes.size();
}
}
}