【问题标题】:ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable | how to fixArrayAdapter.ArrayAdapter(Context,int,int) 不适用 |怎么修
【发布时间】:2020-05-12 20:25:38
【问题描述】:

嘿,我遇到错误 |列表视图不起作用

public class introduction extends Fragment {

    @Override
    public View onCreateView(
            @NonNull LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_intro, container, false);
        TextView t =(TextView)view.findViewById(R.id.textView2);
        t.setText(ag);
        ArrayAdapter<String>adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,b);
        ListView lv= (ListView)view.findViewById(R.id.lb);
        lv.setAdapter(adapter);

        return view;
    }

}

错误: 构造函数 ArrayAdapter.ArrayAdapter(Context,int,int) 不适用 (参数不匹配;介绍不能转换为上下文)

【问题讨论】:

    标签: android-fragments android-arrayadapter


    【解决方案1】:

    问题在于introduction 它是一个片段,而 ArrayAdapter cosnstructor 将 Context 作为参数。所以你不能将片段作为上下文传递。请改用getActivity() 或将 Context 从 Activity 传递给 instruction Fragment 并在 Fragment 中使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 2021-05-18
      相关资源
      最近更新 更多