我有一个Adapter
RecyclerView
文件,可以提供此Android Studio警告:
Private field 'context' is assigned but never accessed
即使我使用this.context = context
。我有另一个有Adapter
文件的工作应用程序,该文件与context
具有完全相同的代码,Android Studio不会对该文件发出警告。我在这里缺少什么?
ContactListAdapter.java
文件:
package com.example.jdw.sixteenthversion;
import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class ContactListAdapter extends RecyclerView.Adapter<ContactListAdapter.ListViewHolder> {
private List<Contact> contactList;
**private Context context**;
private RecyclerItemClickListener recyclerItemClickListener;
public ContactListAdapter(Context context) {
this.context = context;
this.contactList = new ArrayList<>();
}
这是工作应用的ContactListAdapter.java
文件,没有工作室警告:
package com.wimso.android_sqlite.adapter;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
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 com.wimso.android_sqlite.R;
import com.wimso.android_sqlite.listener.RecyclerItemClickListener;
import com.wimso.android_sqlite.model.Contact;
import com.wimso.android_sqlite.widget.LetterTile;
import java.util.ArrayList;
import java.util.List;
public class ContactListAdapter extends RecyclerView.Adapter<ContactListAdapter.ContactHolder>{
private List<Contact> contactList;
**private Context context**;
private RecyclerItemClickListener recyclerItemClickListener;
public ContactListAdapter(Context context) {
this.context = context;
this.contactList = new ArrayList<>();
}
答案 0 :(得分:0)
此警告表示您不在课堂上使用context
字段。如果你不需要它,你可以删除它。除非你不删除它,否则不会有问题。