我在Android中有可扩展的list
,当点击进入子级时,我可见并且看不见View
。我的问题是我必须单击多次单击才能执行操作。如何只需点击一下即可完成此操作。
以下是我的代码:
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,final int groupPosition, final int childPosition,long id) {
final View container =v.findViewById(R.id.container);
TextView tvQuestion = (TextView) v.findViewById(R.id.tvQuestion);
tvQuestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (container.getVisibility() == View.GONE) {
container.setVisibility(View.VISIBLE);
} else {
container.setVisibility(View.GONE);
}
}
});
return false;
}
});
答案 0 :(得分:0)
在这样的适配器中添加clickListner。
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
...your code...
tvQuestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (container.getVisibility() == View.GONE) {
container.setVisibility(View.VISIBLE);
} else {
container.setVisibility(View.GONE);
});
}
});