我从webservice加载了recyclerview数据。当列表大小很大时,活动在滚动时崩溃。但该活动仅在Lollipop设备上崩溃。在Marshmellow设备中它运行良好。有人可以帮忙吗?在此先感谢。
公共类ActivityDisplayTasksforRating扩展AppCompatActivity实现CustomDatePickerListener {
boolean shouldExecuteOnResume;
private RecyclerView recyclerVw_rating;
private TaskRatingAdapter mAdapter;
private LinearLayout lLayout_no_data;
private NetworkClass networkClass = new NetworkClass();
private String mUserId, mStartDate, mEndDate;
private List<TaskApprovalListNew.OverdueRatingReport> mTaskApprovalList = new ArrayList<>();
private ImageView btn_Sync, imgVw_menu, imgV_calendarList;
private TextView txtVw_start_end_date,txtVw_dashboardTitle;
private CustomProgress mcustomprogress;
private CircularImageView imgVw_profile_image;
private String mProfile_image_url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating);
shouldExecuteOnResume = false;
getViewCasting(); // Casting the views
Intent intent = getIntent();
if (intent.hasExtra("profile_image"))
{
mProfile_image_url = intent.getStringExtra("profile_image");
}
if (mProfile_image_url!=null)
{
Picasso.with(ActivityDisplayTasksforRating.this).load(mProfile_image_url).error(R.drawable.zoonooz).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).placeholder(R.drawable.zoonooz).skipMemoryCache().into(imgVw_profile_image);
}
txtVw_dashboardTitle.setText("Task Approval List");
imgV_calendarList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// shows the custom date picker dialog
CustomDatePicker alertDialog = new CustomDatePicker(ActivityDisplayTasksforRating.this, true, ActivityDisplayTasksforRating.this);
alertDialog.getWindow ().setBackgroundDrawableResource(android.R.color.transparent);
alertDialog.show();
}
});
getTaskDataforRating(mStartDate, mEndDate);
}
public void getViewCasting() {
recyclerVw_rating = (RecyclerView) findViewById(R.id.recyclerVw_common);
lLayout_no_data = (LinearLayout) findViewById(R.id.lLayout_no_data);
btn_Sync = (ImageView) findViewById(R.id.btn_Sync);
imgVw_menu = (ImageView) findViewById(R.id.imgVw_menu);
imgV_calendarList = (ImageView) findViewById(R.id.imgV_calendarList);
txtVw_start_end_date = (TextView) findViewById(R.id.txtVw_start_end_date);
txtVw_dashboardTitle = (TextView) findViewById(R.id.txtVw_dashboardTitle);
imgVw_profile_image = (CircularImageView)findViewById(R.id.imgVw_profile_image);
imgV_calendarList.setVisibility(View.VISIBLE);
imgVw_menu.setVisibility(View.GONE);
btn_Sync.setVisibility(View.GONE);
}
public void initRecyclerview()
{
if (mTaskApprovalList.size()>0) {
System.out.println("=========list size"+mTaskApprovalList.size());
recyclerVw_rating.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(ActivityDisplayTasksforRating.this, 1);
recyclerVw_rating.setLayoutManager(layoutManager);
mAdapter = new TaskRatingAdapter(ActivityDisplayTasksforRating.this, mTaskApprovalList);
recyclerVw_rating.setAdapter(mAdapter);
}else
{
System.out.println("=========List empty");
recyclerVw_rating.setVisibility(View.GONE);
lLayout_no_data.setVisibility(View.VISIBLE);
}
}
public void getTaskDataforRating(final String start_date, final String end_date)
{
try {
if (NetworkClass.isOnline(ActivityDisplayTasksforRating.this)) {
if (mTaskApprovalList.size()>0)
{
mTaskApprovalList.clear();
}
Retrofit retrofit = networkClass.callretrofit();
APIInterfaces service = retrofit.create(APIInterfaces.class);
mUserId = PreferenceConnector.readString(ActivityDisplayTasksforRating.this, PreferenceConnector.USER_ID, "");
Call<TaskApprovalListNew> call = service.getTasksforApprovalList(mUserId, start_date, end_date); // "6"
mcustomprogress = new CustomProgress();
mcustomprogress.showCustomDialog(this);
mcustomprogress.setText("Fetching data");
call.enqueue(new Callback<TaskApprovalListNew>() {
@Override
public void onResponse(Call<TaskApprovalListNew> call, retrofit2.Response<TaskApprovalListNew> response) {
if (response.body() != null) if (response.isSuccessful()) {
String status = response.body().getStatus();
mTaskApprovalList = response.body().getOverdueRatingReport();
if (status.equals("NTE_01")) {
initRecyclerview();
} else {
initRecyclerview();
}
if (mcustomprogress != null) {
mcustomprogress.dismiss();
}
}
}
@Override
public void onFailure(Call<TaskApprovalListNew> call, Throwable t) {
if (mcustomprogress != null) {
mcustomprogress.dismiss();
}
Toast.makeText(ActivityDisplayTasksforRating.this, "Failure :" + t.getMessage().toString(), Toast.LENGTH_LONG).show();
}
});
} else {
if (mcustomprogress != null) {
mcustomprogress.dismiss();
}
Toast.makeText(ActivityDisplayTasksforRating.this, "Please connect to internet", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
Log.d("Exception", e.getMessage());
}
}
public class TaskRatingAdapter extends RecyclerView.Adapter<TaskRatingAdapter.ViewHolder>{
private Context mContext;
private List<TaskApprovalListNew.OverdueRatingReport> mManagerProjectsList = new ArrayList<>();
// Passing Project List
public TaskRatingAdapter(Context context, List<TaskApprovalListNew.OverdueRatingReport> project_list) {
mContext = context;
this.mManagerProjectsList = project_list;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_tasks_for_rating, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
System.out.println("=========Position"+position);
System.out.println("=========Task Name"+mManagerProjectsList.get(position).getTaskName());
String profile_image = mManagerProjectsList.get(position).getProfileImage();
if (profile_image!=null)
{
Picasso.with(ActivityDisplayTasksforRating.this).load(profile_image).error(R.drawable.zoonooz).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).placeholder(R.drawable.zoonooz).skipMemoryCache().into(holder.imgVw_user_image);
}
holder.txtVw_author.setText(mManagerProjectsList.get(position).getUserName());
holder.txtVw_task_title.setText(mManagerProjectsList.get(position).getTaskName());
holder.txtVw_proj_name.setText(mManagerProjectsList.get(position).getProject_name());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(ActivityDisplayTasksforRating.this, TaskRatingActivity.class);
intent.putExtra("task_id",mManagerProjectsList.get(position).getTaskId());
intent.putExtra("total_hours",mManagerProjectsList.get(position).getTotalHours());
intent.putExtra("user_id",mManagerProjectsList.get(position).getUserId()); // Passing the task_id, total_hours and user id to sync activity
startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return mManagerProjectsList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView txtVw_task_title,txtVw_proj_name,txtVw_author,txtVw_task_day,txtVw_task_month,txtVw_task_year,txtVw_task_start_time;;
private CircularImageView imgVw_user_image;
public ViewHolder(View view) {
super(view);
txtVw_task_title = (TextView) view.findViewById(R.id.txtVw_task_title);
txtVw_proj_name = (TextView) view.findViewById(R.id.txtVw_proj_name);
txtVw_author = (TextView) view.findViewById(R.id.txtVw_author);
txtVw_task_day = (TextView) view.findViewById(R.id.txtVw_task_day);
txtVw_task_month = (TextView) view.findViewById(R.id.txtVw_task_month);
txtVw_task_year = (TextView) view.findViewById(R.id.txtVw_task_year);
txtVw_task_start_time = (TextView) view.findViewById(R.id.txtVw_task_start_time);
imgVw_user_image = (CircularImageView) view.findViewById(R.id.imgVw_user_image);
}
}
}