- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我只想一次展开父列表中的一项,目前我的 onCreate 代码如下。 (按我的意愿工作,但是一次只允许一个父打开的方法不起作用)
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
//FOR LEVEL 1 SCREEN
this,
createGroupList(), // METHOD TO CREATE PARENTLIST Creating group List.
R.layout.group_row, // REF TO XML FILENAME.
new String[] { "Group Item" }, // STRING ARRAY HOLDING ONE KEY THAT REF'S ALL PARENT LIST ITEMS.
new int[] { R.id.row_name }, // REF TO I.D. OF PARENT XML. ID of each group item.-Data under the key goes into this TextView.
createChildList(), // METHOD TO CREATE CHILD LST. childData describes second-level entries.
R.layout.child_row, // XMLFILE NAME FOR CHILD LIST.Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // KEY FOR CHILD ITEMS IN HASHMAP. Keys in childData maps to display.
new int[] { R.id.grp_child} // XML ID FOR TEXTVIEW. Data under the keys above go into these TextViews.
);
setListAdapter( expListAdapter ); // setting the adapter in the list.
//**THIS IS WHAT I DONT KNOW HOW TO CODE:**
list = (ExpandableListView) findViewById(R.id.row_name);
list.setAdapter( expListAdapter);
list.setGroupIndicator(null);
list.setOnGroupExpandListener(new OnGroupExpandListener() {
public void onGroupExpand(int groupPosition) {
int len = expListAdapter.getGroupCount();
for (int i = 0; i < len; i++) {
if (i != groupPosition) {
list.collapseGroup(i);
}
}
}
});
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
我理解上面的代码,但是,我不使用 expandableListViews,我将我的程序引用到我的 .xml 文件中,其中包含可扩展列表的布局。所以我不知道如何将以上内容应用到我的程序中......
主.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bkg"/>
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No items"/>
</LinearLayout>
不知道怎么申请的方法如下:
list = (ExpandableListView) findViewById(R.id.row_name);
list.setAdapter( expListAdapter);
list.setGroupIndicator(null);
list.setOnGroupExpandListener(new OnGroupExpandListener() {
public void onGroupExpand(int groupPosition) {
int len = expListAdapter.getGroupCount();
for (int i = 0; i < len; i++) {
if (i != groupPosition) {
list.collapseGroup(i);
}
}
}
});
1) 如何将“列表”引用到我的可扩展列表 Activity 中?
列表在类中定义为private ExpandableListView list;
我现在没有任何错误,但该方法不起作用。
非常感谢任何帮助!
最佳答案
// Declare variable
private static int prev = -1;
// and OnGroupExpandListener implement
mExpandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if(prev!=-1)
{
mExpandableList.collapseGroup(prev);
}
prev=groupPosition;
}
});
更新解决方案
mExpandableList.setOnGroupExpandListener(new OnGroupExpandListener() {
// Keep track of previous expanded parent
int previousGroup = -1;
@Override
public void onGroupExpand(int groupPosition) {
// Collapse previous parent if expanded.
if ((previousGroup != -1) && (groupPosition != previousGroup)) {
mExpandableList.collapseGroup(previousGroup);
}
previousGroup = groupPosition;
}
});
关于android - Android 中的 ExpandableLists,我想一次只允许扩展一个父列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9119709/
我正在关注本教程:ExpandableListView 但在我的设备(Samsung Galaxy S i9000)中,文本与可扩展图标重叠,如图所示。 我怎样才能避免这种情况?谢谢 最佳答案 这个例
我希望在长按 ExpandableList 时为每个组创建一个菜单。但目前只有非空组在长按时显示蓝色背景并且可以选择。所有空组都不会对长按使用react。 我使用 registerForContext
我正在尝试显示一个多深度的可扩展列表。也就是说,我们有一个表头 ID |学校 |年级 |姓名 我想展示一个可扩展的列表学校 - 年级 - 姓名 学校是第一个深度,等级是第二个深度,名字是叶节点。我了解
我有一个 expandableList,在子元素中我添加了一些 EditText、复选框和微调器。这些已正确创建和显示。选中复选框后会显示其他 EditText 和微调器,然后用户可以添加文本并从微调
问题很简单,但我做不出来。我有一个带有 3 个标题的可扩展列表,它们可以是填充的也可以是空的。 我希望在您展开一个空的组时显示一个简单的 TextView ,我已经找了一段时间但似乎没有任何效果。我不
每个组 View 我只有 1 个 subview ,它是从布局 .xml 文件扩展而来的。我希望为 subview 设置动画,以便在显示子项时,其下方的列表项向下滑动。我尝试了一些动画,但问题是首先使
我正在尝试个性化 ExpandableLisTview 我创造 Iterator.Xml:带有 ExpandableList View group.xml:具有简单 TextView 和 Button
我正在创建使用可扩展列表 View 的android应用,每个子项都包括图像 View 和扩展了 BaseExpandableAdapter 的文本。 图像在可绘制的forlder中,我使用数组检索它
我一直在使用自定义的 ExpandableList(参见下面的示例图片),其中每个项目始终有一个子项。这个 child 由三部分组成。每个部分都有一个标题(红色条),下面是一个空项目或项目列表。此列表
这个问题可能很菜鸟,但我就是找不到正确的解决方案。 所以这是我的问题: 我想在多个 ExpandableLists(比如说 5 个)中显示数据(一个 java.util.List 和我的 TaskOb
我只想一次展开父列表中的一项,目前我的 onCreate 代码如下。 (按我的意愿工作,但是一次只允许一个父打开的方法不起作用) public void onCreate(Bundle savedIn
我根据要编辑的editText的结果,得到Expandable List里面的editText为childcount的个数。但 editText 位置总是不同或 childcount 出错,我收到此错
这是我的 XML 布局文件,我正在使用 chrisbanes pull 来刷新库 here 出于某种原因,它只会显示可点击项目的可展开列表中的第一
我有关于 onChildClickListener 的代码,如下面的代码 fragment OnChildClickListener occl = new OnChildClickListener()
如何折叠 Expandable List 中的所有 ChildView 组。现在我有两个按钮来控制 Activity 上的全部展开和全部折叠。可扩展按钮没问题,它正在工作,但我不知道如何折叠所有 Ch
我想从 SQLite 数据库获取数据并通过 SimpleCursorTreeAdapter 填充我的 ExpandableListView,但它在某些地方失败了。我真的找不到问题所在,甚至不知道异常发
我是一名优秀的程序员,十分优秀!