可扩展列表 android 子项的问题
issue with expandable list android child
我在 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;
}
});
像这样在适配器中添加点击监听器。
@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);
});
}
});
我在 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;
}
});
像这样在适配器中添加点击监听器。
@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);
});
}
});