- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我需要以下问题的帮助:
有没有办法在“expendableListView”中添加一个按钮作为最后一个子项?
该按钮应位于“短文本”字段下方。
如果您需要任何进一步的信息,请发表评论,我会提供。
最佳答案
你的 ExpandableListView
应该由一些数据模型支持。在每个列表项行中,您将在 View (TextView 或 Button)中显示一个文本。所以首先让自己成为一个包含这些信息的类:
public class RowData {
public static final int TYPE_TEXT = 0;
public static final int TYPE_BUTTON = 1;
private String label;
private int type;
public RowData(String label, int type) {
this.label = label;
this.type = type;
}
public RowData(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
public int getType() {
return type;
}
}
最简单的模型(因为我们不了解您的代码)是 LinkedHashMap<String, List<RowData>>
.这些键指的是组数据(“00010”、“00020”、“00030”等),而附加到这些键的每个值指的是组子项(例如,对于“00010”,您将有 ["Material Group: No找到的信息”等])。现在,在您的 Activity 中保留对此数据模型的引用:
private Map<String, List<RowData>> myData = new LinkedHashMap<String, List<RowData>>();
您需要保留对 ExpandableListView 适配器的引用:
private BaseExpandableListAdapter adapter = new CustomSpecificAdapter(yourActivityContext, myData);
当您需要添加额外的字段时,您只需将其添加到数据模型对象中即可:
myData.get("00010").add(new RowData("Button value", RowData.TYPE_BUTTON));
或 TextView
: myData.get("00010").add(new RowData("TextView value"));并通知适配器:
adapter.notifyDataSetChanged();
这将更新可扩展列表。但是,您需要为每一行指定您将拥有什么样的 View ,每个位置将具有什么类型,因为这与 View 回收非常相关。所以你的相关CustomSpecificAdapter
方法可能类似于:public class CustomSpecificAdapter extends BaseExpandableListAdapter
private LinkedHashMap<String, List<RowData>> modelData;
private Context context;
public CustomSpecificAdapter(Context context, LinkedHashMap<String, List<RowData>> modelData) {
this.context = context;
this.modelData = modelData;
}
private RowData getMyDataObj(int groupPosition, int childPosition) {
/**
* safe to do this since we are using a LinkedHashMap
* */
List<List<RowData>> children = new ArrayList<List<RowData>>(modelData.values());
return children.get(groupPosition).get(childPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return getMyDataObj(groupPosition, childPosition);
}
@Override
public int getChildTypeCount() {
/**
* since you will have a button and a textview there will be 2 types of views
* */
return 2;
}
@Override
public int getChildType(int groupPosition, int childPosition) {
RowData data = getMyDataObj(groupPosition, childPosition);
if (data.getType() == RowData.TYPE_TEXT) {
return 0;
}
// for button
return 1;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
/**
* this is the intersting part
* */
RowData data = getMyDataObj(groupPosition, childPosition);
TextView myTv = null;
if(convertView == null) {
if(data.getType() == RowData.TYPE_BUTTON) {
convertView = // inflate from button layout, in fact it's best to have only a <Button ... /> in the XML layout
} else {
convertView = // inflate from TextView layout, in fact it's best to have only a <Button ... /> in the XML layout
}
}
/**
* Have the same id for both TextView and Button - Button extends from TextView and so setText() method is available through polimorphysm. Also no need for ViewHolder as getViewById() will refer to itself.
* */
myTv = (TextView) convertView.findViewById(the_same_id_in_both_xml_files);
myTv.setText(data.getLabel());
return convertView;
}
关于android - 将按钮作为最后一个子项添加到可扩展 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18181187/
我正在尝试将 margin-left:20px 分配给表单内的所有 div,其类包含编辑,具有以下内容: form.edit > div { margin-left:20px; } 我的想法
我有这个 xpath: .//*[@id='some_id']/td//div 现在我想选择特定类型的 div 的任何子项,例如每个子项是标签或跨度。像这样的东西 .//*[@id='some_id'
我有一个包含包含用户信息的键列表的键,现在当我的表单加载时,我想将这些键作为数组获取。我该怎么做?我找到了获取计数的方法,但仍然不知道如何获取这些 key 。 最佳答案 您可以使用 Microsoft
关闭。这个问题需要更多 focused 。它目前不接受答案。 想要改进这个问题?更新问题,使其只关注 editing this post 的一个问题。 关闭 6 年前。 Improve this q
我正在通过一些在线教程来学习 AEM。根据教程,创建组件时,需要在 Allowed Parents 或 Allowed Children 中输入一些值。但是,我在窗口中看不到这样的选项。当我尝试创建组
我需要将 MDI 子窗体的创建集中到 Delphi (VCL) 中的一个独特过程中。这个想法是每次创建 MDI 子窗体时执行一些操作,无论其类型如何,即将其标题名称添加到列表中以访问该 MDI 子窗体
我试图在 TreeView 中获取所选节点的所有子节点,但遇到了一些问题。 以这个 TreeView 为例: 我想将所有子节点变为黄色突出显示的“文件夹”节点,这将是旁边有一条蓝线的子节点。 这是我尝
我在最小化我所有的 MDIChildren 时遇到了麻烦,遇到了 MDIChild to minimize not activated properly 我最小化所有 child 的代码是: proc
我使用下面的代码通过单击系统关闭按钮来关闭 MDI 子窗体,它工作正常: procedure Tfrm_main.FormClose(Sender: TObject; var Action: TC
仅当我指定对象的完整路径时,我才能通过指定特定子键来查找 Firebase 对象。这是为什么? 这有效 ref.child(`users/${user.uid}/watchlist/${key}`)
每当我单击工具栏菜单时,它每次都会显示新表单。我想阻止它一次又一次地显示相同的表单。在给出的代码中,form2 一次又一次地显示。我想停止它,以便它显示一次。 喜欢: private void new
我想知道是否有一种方法可以通过遍历父节点的 vector 来获取子节点中的数据。我有一个我计划经常更改的 XML 文件,因此我想避免对属性名称进行硬编码。因此,我想在我的子节点中提取数据而不使用 pt
假设我有以下 YAML 文件: - key1: value # and so on... key99: value key100: subkey1: value # an
我不是代码天才,而是行动脚本爱好者。 你能帮我吗? 我有一个函数,根据选择的对象,该函数将事件监听器调用已经在舞台上的一组“子项目”(我想在单击时重新使用具有更改参数的子项目,而不是创建多个实例和代码
我需要一些帮助来查询分层数据。这是一个简单的表,其中 parent_id 引用 id 并且对于根条目可能为 null。 create table edition ( id
我尝试获得一个简单的 GEF 编辑器。我有一个 GraphicalEditorWithPalette 来创建我的示例模型。我有一个覆盖 createFigure 和 getModelChildren
我正在尝试搜索其中包含子项(文本区域)的表格单元格。我努力了td.children.value,td.childNodes.value,td.firstChild.value,td.lastChild
我有一个 mdi 父 form 并且我在运行时通过以下代码将我的其他 form 作为 mdi 子窗体打开: private void MenuItem_Click(object sender, Eve
我在 Activity 中加载了一个 GridView,其中存在 fragment 。 GridView 本身并不位于 Fragment 中。我通过 BaseAdapter 创建了一个客户适配器,一切
我在导航 Controller 中有两个 child (根 child 和第二个 child )。我通常先去找根 child ,然后再去找第二个 child 。这允许我使用导航 Controller
我是一名优秀的程序员,十分优秀!