找不到符号方法OnClickListener android

我正在尝试以编程方式生成一组按钮,并使它们可以在片段中单击。 但是,我得到:

error: cannot find symbol method OnClickListener(TagsFragment) 

到目前为止,这是我的代码:

 public class TagsFragment extends Fragment implements View.OnClickListener { public TagsFragment() { } public static TagsFragment newInstance() { TagsFragment fragment = new TagsFragment(); Bundle args = new Bundle(); fragment.setArguments(args); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_tags, container, false); Bundle bundle = this.getArguments(); String[] tags = bundle.getStringArray("tags"); for(String item : tags) { //System.out.println(item); Button tag = new Button(getActivity()); tag.setText(item); tag.setTag("newtag"); tag.OnClickListener(this); ((LinearLayout) rootView).addView(tag); } return rootView; } @Override public void onClick(View view) { System.out.println("onclick"); } } 

此外,android studio突出显示此行上的“标记”:

 tag.OnClickListener(this); 

我有这个:“ Expected class or package

替换此行:

  tag.OnClickListener(this); 

用:

 tag.setOnClickListener(this);