我想提前使用CustomAdapter但是上下文问题。我不明白这将是什么背景。我使用 Blocklist.this 上下文,但它不起作用。 请帮助我。
Blocklist.java
private ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blocklist);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
adapter = new CustomAdapter(**Blocklist.this**, R.layout.custom_textview, arrayList);
listView = (ListView) findViewById(R.id.blockList);
listView.setAdapter(adapter);
CustomAdapter.java
我认为公共类CustomAdapter中的问题扩展了ArrayAdapter 行,因为我在Blocklist.java类中使用 HashMap 。如果这样,请告诉我代码应该使用还是什么不使用?
public class CustomAdapter extends ArrayAdapter<String> {
private SparseBooleanArray mSelectedItemsIds;
private LayoutInflater inflater;
private Context mContext;
private List<String> list;
public CustomAdapter (Context context, int resourceId, List<String> list) {
super(context, resourceId, list);
mSelectedItemsIds = new SparseBooleanArray();
mContext = context;
inflater = LayoutInflater.from(mContext);
this.list = list;
}