【发布时间】:2015-12-09 22:01:54
【问题描述】:
这是我的整个活动代码,如果需要,我也可以发布我的 xml。
public class Main_Activityextends AppCompatActivity {
private RecyclerView recyclerview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
recyclerview.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
List<ExpandableListViewAdapter.Item> data = new ArrayList<>();
data.add(new ExpandableListViewAdapter.Item(ExpandableListViewAdapter.HEADER, "Terms of usage"));
data.add(new ExpandableListViewAdapter.Item(ExpandableListViewAdapter.CHILD, "never eat"));
data.add(new ExpandableListViewAdapter.Item(ExpandableListViewAdapter.CHILD, "bluhhhhh"));
recyclerview.setAdapter(new ExpandableListViewAdapter(data));
recyclerview.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
return true;
}
});
代码在没有clickListener 的情况下完美运行,但我希望在单击数组的某个子项时发生一个动作,但现在它显示Cannot resolve method setOnChildClickListener(anonymous android.widget.ExpendableListView.OnChildClickListener) 尽管recycleView 是我的Adapter,任何帮助将不胜感激
【问题讨论】:
-
尝试在您的子视图中添加
android:descendantFocusability="blocksDescendants" -
还是一样的结果
-
你有没有吐司之类的东西要知道它没有起火?
-
没有因为出现以下错误导致无法运行
Cannot resolve method setOnChildClickListener(anonymous android.widget.ExpendableListView.OnChildClickListener) -
在你的
onCreate()添加这个:isChildSelectable(true);
标签: java android arraylist expandablelistview