问题描述
我想实现这样的事情。该扩展列表包括某些类别和名称的父被点击时,它显示该类别所有的孩子的名单。现在,假设我要动态地添加一个孩子的任何类别?我怎么做 ?我总是与每一位家长在列表中点击哪个将增加一个新的子下一个按钮?
I am trying to achieve something like this.The Expandable List consists of the names of certain categories and when a parent is clicked, it shows the list of all the children in that category.Now, suppose I want dynamically add a child to any category ?How do I do that ?Do I keep a button with every parent in the list clicking on which would add a new child under it ?
但环顾四周在不同的论坛,我才明白,这是不是真的很容易设置一个按钮单击处理每一位家长的内部。但是,如果这是唯一的出路,任何人都可以给我一些样品code吗?
But looking around in different forums, I came to realize that it is not really easy to set a button click handler inside every parent. But if that is the only way, can anyone give me some sample code please ?
我发现这个线程,但没能在我的code来实现它。Android行变为不可点击巴顿
I found this thread but wasn't able to implement it in my code.Android Row becomes Unclickable with Button
推荐答案
添加一个按钮组视图不应该是困难的。
Adding a button to the group view shouldn't be that difficult.
我相信下面的应该工作(虽然我没有使用数组支持ExpandableListView来测试项目)。
I believe the below should work (although I don't have a project using an array backed ExpandableListView to test on).
我不知道你的小组排布置,所以我会做一个在这里以供参考。
I don't know your group row layout, so I'll make one up here for reference purposes.
group_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/addbutton"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Add"
android:textSize="12dp" />
</LinearLayout>
然后从您的适配器的 getGroupView
方法:
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
View convertView = View.inflate(getApplicationContext(), R.layout.group_layout, null);
Button addButton = (Button)convertView.findViewById(R.id.addButton);
addButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// your code to add to the child list
}
});
}
TextView textView = (TextView)convertView.findViewById(R.id.text1);
textView.setText(getGroup(groupPosition).toString());
return convertView;
}
这篇关于Android的ExpandableListView家长巴顿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!