本文介绍了找不到符号法OnClickListener机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图生成一组按钮编程,使他们在一个片段点击。不过,我得到:
I'm trying to generate a group of buttons programatically and make them clickable in a fragment. However, I get:
error: cannot find symbol method OnClickListener(TagsFragment)
这是我的code到目前为止:
That's my code so far:
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");
}
}
此外,机器人工作室突出在这条线的标签:
Also, android studio highlights the "tag" on this line:
tag.OnClickListener(this);
和我有这样的:预期类或包
推荐答案
替换这行:
tag.OnClickListener(this);
与
tag.setOnClickListener(this);
这篇关于找不到符号法OnClickListener机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!