小编Aug*_*ust的帖子

RecyclerView.Adapter的上下文

我想添加ProgressDialog一个适配器。AFAIK,.this用于活动和getActivity.getApplicationContext()片段。那适配器呢?可能吗?

Unable to add window -- token null is not valid; is your activity running?使用时出现错误mContext.getApplicationContext()

编辑:

在一个片段中,我将卡片显示为

allGroupsView = (RecyclerView) rootView.findViewById(R.id.allGroupsView);
adapterGroup = new AdapterGroup(getActivity().getApplicationContext(), results);
allGroupsView.setAdapter(adapterGroup);
allGroupsView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
Run Code Online (Sandbox Code Playgroud)

在班上 AdapterGroup

public class AdapterGroup extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private Context mContext;
private LayoutInflater inflater;
List<DataGroup> data= Collections.emptyList();
DataGroup current;

public AdapterGroup(Context context, List<DataGroup> results) {
    this.mContext = context;
    inflater = LayoutInflater.from(mContext);
    this.data = results;
}

// Inflate the layout when viewholder created …
Run Code Online (Sandbox Code Playgroud)

android android-context android-adapter

1
推荐指数
1
解决办法
6170
查看次数

标签 统计

android ×1

android-adapter ×1

android-context ×1