我需要在可扩展列表的父视图中添加一个按钮
我正在尝试向可扩展列表的父视图添加一个按钮。这是我的父视图的布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/explist_indicator"
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:src="@drawable/expander_group" />
<TextView
android:id="@+id/contacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:paddingLeft="20dp"
android:text="@string/contacts"
android:textSize="28dp" >
</TextView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:background="@drawable/plus"
android:text="Button" />
</LinearLayout>
我像平常一样将按钮添加到 java 类中,但是当我尝试添加侦听器时出现空指针异常。我添加此按钮来选择/取消选择特定父级的所有子级。任何帮助都会很棒。
I am trying to add a button to the parentview of an expandablelist. This is my layout for the parentview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/explist_indicator"
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:src="@drawable/expander_group" />
<TextView
android:id="@+id/contacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:paddingLeft="20dp"
android:text="@string/contacts"
android:textSize="28dp" >
</TextView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:background="@drawable/plus"
android:text="Button" />
</LinearLayout>
I add the button to the java class like normal, but get a null pointer exception when i try to add a listener. I am adding this button to select/deselect all the children of the particular parent. Any help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加自定义图像作为组下拉指示器,只需创建下拉列表的图像,然后通过其组指示器属性将其连接到可扩展列表视图。组指示器是一个可绘制的 xml 文件,定义 state_expanded 和可绘制状态使用哪个图像。您仍然需要在代码中在运行时为可扩展列表视图设置组指示器。
You can add a custom image to serve as the group drop down indicator by simply creating images of the drop down then hook it up to the expandable list view via it's group indicator property. The group indicator is a drawable xml file defining which image to use by state_expanded and drawable states. You will still need in code to set the group indicator at run time for the expandable list view.