【发布时间】:2016-08-27 02:48:59
【问题描述】:
我有一个片段,它代表我项目的一个选项卡。该片段承载一个 ExpandableListAdapter。可扩展列表只是每个显示一些信息的组一个 TextView 子项。
我想要实现的是在展开的 TextView 上实现双击。双击 TextView 后,它将折叠该组。
我试图折叠适配器内的组,但由于某种原因它得到了 SO。我知道我必须实现一个 GestureDetector,但我似乎无法在适配器甚至片段中实现它。
我的片段:
public class FragmentProgramInfo extends Fragment
{
View view;
ExpandableListView expandableListView;
ExpandableListAdapterProgramInfo expandableListAdapterProgramInfo;
public FragmentProgramInfo()
{}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.inflate(R.layout.fragment_program_info, container, false);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
expandableListAdapterProgramInfo = new ExpandableListAdapterProgramInfo(getActivity());
expandableListView = (ExpandableListView) view.findViewById(R.id.ELV_program_info_list);
expandableListView.setAdapter(expandableListAdapterProgramInfo);
}
}
我的适配器:
public class ExpandableListAdapterProgramInfo extends BaseExpandableListAdapter
{
Activity context;
View masterView;
private String[] listGroups;
private String[][] listChilds;
public ExpandableListAdapterProgramInfo(Activity context)
{
this.context = context;
interfaceExpandableListAdapterProgramInfo = (InterfaceExpandableListAdapterProgramInfo) context;
masterView = context.getWindow().getDecorView().findViewById(android.R.id.content);
/// Intitialize strings of listGroups and listChilds
}
@Override
public View getGroupView(final int listGroupPosition, boolean isExpanded, View view, ViewGroup viewGroup)
{
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(view == null)
view = layoutInflater.inflate(R.layout.list_group_program_info, viewGroup, false);
TextView tvListGroupProgramInfo = (TextView) view.findViewById(R.id.TV_list_group_program_info);
tvListGroupProgramInfo.setText(getGroup(listGroupPosition).toString());
return view;
}
@Override
public View getChildView(final int listGroupPosition, final int listChildPosition, boolean isLastChild,
View view, ViewGroup viewGroup)
{
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(R.layout.list_child_program_info, viewGroup, false);
TextView tvListChildProgramInfo = (TextView) view.findViewById(R.id.TV_list_child_program_info);
tvListChildProgramInfo.setText(listChilds[listGroupPosition][listChildPosition]);
return view;
}
/// Override other methods of ELV
}
【问题讨论】:
标签: android expandablelistview expandablelistadapter gesturedetector