- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个带有 Activity
的 Android 应用,里面有一个 ExpanableListView
。
我想要的是 ExpandableListView
在我点击它时滚动所选组的标题,如果它不能(因为没有足够的垂直空间),我想要它滚动到底部。
如果我在 ListView 底部有更多空间(即其他组)时点击一个组,则一切正常,并且 ListView 滚动以显示子项。(编辑:不,它没有;它只在第一次点击时正常工作,所有连续的尝试都不会导致滚动)
但是,如果 ListView 没有空间,则不会发生滚动,组会展开,然后我可以进一步向下滚动以查看子组。
我尝试了很多方法,例如覆盖“onGroupClick
”和调用“smoothScrollToPosition
”,但结果几乎相同。
任何帮助将不胜感激。
最佳答案
您可以尝试类似下面的操作。完美运行:
public static class LineupFragment extends Fragment {
View rootView;
ExpandableListView lv;
private String[] groups;
private String[][] children;
public LineupFragment() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
groups = new String[] { "Test Header 1", "Test Header 2", "Test Header 3", "Test Header 4" };
children = new String [][] {
{ "s simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." },
{ "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of comes from a line in section 1.10.32." },
{ "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)." },
{ "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc." }
};
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_lineup, container, false);
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
lv = (ExpandableListView) view.findViewById(R.id.expListView);
lv.setAdapter(new ExpandableListAdapter(groups, children));
lv.setGroupIndicator(null);
}
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private final LayoutInflater inf;
private String[] groups;
private String[][] children;
public ExpandableListAdapter(String[] groups, String[][] children) {
this.groups = groups;
this.children = children;
inf = LayoutInflater.from(getActivity());
}
@Override
public int getGroupCount() {
return groups.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inf.inflate(R.layout.list_item, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.lblListItem);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getChild(groupPosition, childPosition).toString());
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inf.inflate(R.layout.list_group, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.lblListHeader);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getGroup(groupPosition).toString());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
private class ViewHolder {
TextView text;
}
}
关于android - 如果在底部,ExpandableListView 不会滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13946601/
我只是想知道Mvvmmcross框架中是否潜藏着ExpandableListViews或与之相似的功能,还是这种控件不适用于多平台要求。 的功能在 http://deapsquatter.blogsp
我想知道是否可以将一个 ExpandableListView 作为另一个 ExpandableListView 的一个元素的一个子元素。谢谢 最佳答案 是的。可以在可扩展 ListView 中创建可扩
现在我想使用 ExpandableListView 来显示我的数据,我想更改项目左侧的图标或让它消失。有人可以给我一个建议吗。 谢谢。 最佳答案 setGroupIndicator(null) 应该让
我在 expandablelistview 子项目中有一个 edittext。然后,我在这个 edittext 中输入了一个文本,但是每当我点击其他 expandablelistview 标题时,我输
我正在尝试弄清楚如何构建包含(许多)的 View : PARENT1(可勾选、可扩展) CHILD1(单选按钮) CHILD2(单选按钮) ... PARENT2(可勾选、可扩展) CHILD1(可检
所以我刚刚进入了 ExpandableListView 领域,并希望在 DrawerLayout 中制作一个只有一组和 3 个 child 的简单列表 这是我的适配器代码: public cl
我是 Android 开发新手。我关注了this显示 ExpandableListView 及其正常工作的教程。如果我按所有组,那么所有组都会展开。 我一次只想扩展一组。一开始,第一个组将自动展开,如
我是 Android 新手。我想创建一个可扩展的 ListView,其中 1 行具有必须在 manin 线程中指定的自定义信息,而不是在布局中进行硬编码。 我想要一个图像和 2 个 TextView
我的应用程序中有一个 ExpandableListView。我想让子布局比组标题窄一点,并保持居中。由于一些视觉效果,我必须从代码中设置布局参数,但是我似乎找不到最好的解决方案,尝试从 xml 更
我正在将 JSON 解析为 ExpandableListView,在每个子项上,用户可以选择他想要拥有的 +/- 按钮的每个子项的数量。 +/- 按钮连接到 TextView,其中显示每个子项的总金额
我希望我的团队能够在第一时间扩大。然后它应该像往常一样运行(单击指示器后折叠/展开) 我找不到解决此问题的任何有效解决方案。 最佳答案 循环遍历所有组并使用expandGroup()您的 Expand
我正在编写一个 Android 应用程序,我决定使用可扩展 ListView 。我拥有所需的一切,列表工作正常,但是当我填充它时,组的顺序似乎与应有的顺序不同,这是一个示例: 如您所见,子值很好,只有
我在组项目的 ExpandableListView 中添加了 EditText,之后当我单击组项目时,不会出现包含子项目的列表。可能是什么问题?在这种情况下,这个列表是否可以扩展?或者禁止在Expan
当我单击组 View 时,可扩展列表的顺序会发生变化 我发现有人有类似的问题 here 顺序似乎是随机的,我不明白发生了什么。 这是我的代码,我知道它很乱,我已经重写了很多次。 public clas
我是 Android 编程的新手,我一直在思考如何做到这一点……我想创建一个 ExpandableListView,其中包含相同的子项 XML(包含添加、编辑和删除按钮)填充在所有组项目中。 有人可以
我在 Android 抽屉导航中使用 ExpandableListsViews 而不是菜单。而 OnExpandlistner 我正在改变背景颜色。前两个项目表现正常,它们的背景颜色发生了变化。但最后
我对 ExpandableListView 有疑问:在我的应用程序中,我使用了 ExpandableListView 并用我的适配器填充它“类 MyExpandableListAdapter 扩展了
我正在使用 Fedor 的适配器和图像加载器将图像延迟加载到可扩展 ListView 中。 ( Lazy load of images in ListView ) 它运行良好,但有一个问题。仅当 Im
关注this教程我能够制作一个大致这样布局的 View : Group1 child1 child2 group2 child1 child2 但是我想要更多的嵌套: grou
Blockquote 我在 android 中使用 ExpandableListView 这是适配器类中getChildView的代码: @Override public View g
我是一名优秀的程序员,十分优秀!