Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在recycler view.Adapter中将注释添加到listview中_Java_Android_Listview_Android Recyclerview - Fatal编程技术网

Java 如何在recycler view.Adapter中将注释添加到listview中

Java 如何在recycler view.Adapter中将注释添加到listview中,java,android,listview,android-recyclerview,Java,Android,Listview,Android Recyclerview,我需要将点击按钮上的注释放入listview,但我正在使用recycler视图适配器 我得到这个错误: Error:(200, 54) error: no suitable constructor found for ArrayAdapter(<anonymous OnClickListener>,int,ArrayList<String>) constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not app

我需要将点击按钮上的注释放入listview,但我正在使用recycler视图适配器

我得到这个错误:

Error:(200, 54) error: no suitable constructor found for ArrayAdapter(<anonymous OnClickListener>,int,ArrayList<String>)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)
constructor ArrayAdapter.ArrayAdapter(Context,int,String[]) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)
constructor ArrayAdapter.ArrayAdapter(Context,int,List<String>) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)
错误:(200,54)错误:找不到适合ArrayAdapter(,int,ArrayList)的构造函数
构造函数ArrayAdapter.ArrayAdapter(上下文,int,int)不适用
(参数不匹配;无法转换为上下文)
构造函数ArrayAdapter.ArrayAdapter(上下文、int、字符串[])不适用
(参数不匹配;无法转换为上下文)
构造函数ArrayAdapter.ArrayAdapter(上下文、int、列表)不适用
(参数不匹配;无法转换为上下文)
代码如下:

holder.button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //holder.lw.setA
           String commento= (holder.tw.getText().toString());
           // holder.lw.setAdapter(adapter);
             ArrayList<String> arrayList= new ArrayList<String>();
            final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);

            arrayList.add(commento);
            // next thing you have to do is check if your adapter has changed
            holder.lw.setAdapter(adapter);
            adapter.notifyDataSetChanged();


        }

    });
holder.button.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//holder.lw.setA
字符串commento=(holder.tw.getText().toString());
//固定器lw.设置适配器(适配器);
ArrayList ArrayList=新的ArrayList();
最终ArrayAdapter=新的ArrayAdapter(这是android.R.layout.simple\u list\u item\u 1,arrayList);
arrayList.add(commento);
//接下来要做的是检查适配器是否已更改
固定器lw.设置适配器(适配器);
adapter.notifyDataSetChanged();
}
});
有人能帮我吗? 谢谢

将行中的“”替换为上下文

 final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);
视频适配器的构造函数

  public VideoAdapter (Context context) {
       this.mContext = context;
    }
像这样初始化

 final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext , android.R.layout.simple_list_item_1, arrayList);
final ArrayAdapter adapter=新的ArrayAdapter(mContext,android.R.layout.simple\u list\u item\u 1,arrayList);
正如您所看到的,ArrayAdapter的构造函数需要上下文而不是onClickListener引用


注意:您可以在VideoAdapter构造函数中传递尽可能多的参数,这只是向您展示如何传递上下文的一种方式。

替换为
上下文
行中的
最终ArrayAdapter=新ArrayAdapter(此,android.R.layout.simple\u list\u item\u 1,arrayList)@Chithra没有上下文…我留在VideoAdapter extends RecyclerView.Adapter中
 final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext , android.R.layout.simple_list_item_1, arrayList);