ExpandableList View 不展开

2024-01-31

我正在尝试个性化 ExpandableListTview

I create

  • Iterator.Xml:带有 ExpandableList 视图
  • group.xml:带有简单 TextView 和 Button 的相对布局
  • Child.xml:只有一个textView的相对布局

Class:

package Android.MyExapandableListView;

import android.app.Activity;
import android.app.ExpandableListActivity;
import android.os.Bundle;

import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;

public class main extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.iterator);
    ExpandableListView lv =
        (ExpandableListView) this.findViewById(R.id.ExpandableListView);
    MyExpandableListAdapter questions = new MyExpandableListAdapter();
    lv.setAdapter(questions);

  }

  public class MyExpandableListAdapter extends BaseExpandableListAdapter {
    private LayoutInflater inflater = null;
    private String[] groups = { "People Names", "Dog Names", "Cat Names",
        "Fish Names" };
    private String[][] children = { { "Arnold", "Barry", "Chuck", "David" },
        { "Ace", "Bandit", "Cha-Cha", "Deuce" }, { "Fluffy", "Snuggles" },
        { "Goldy", "Bubbles" } };

    public MyExpandableListAdapter(){
      this.inflater = main.this.getLayoutInflater();
    }

    public Object getChild(int groupPosition, int childPosition) {
      return children[groupPosition][childPosition];
    }

    public long getChildId(int groupPosition, int childPosition) {
      return childPosition;
    }

    public int getChildrenCount(int groupPosition) {
      return children[groupPosition].length;
    }

    public Object getGroup(int groupPosition) {
      return groups[groupPosition];
    }

    public int getGroupCount() {
      return groups.length;
    }

    public long getGroupId(int groupPosition) {
      return groupPosition;
    }

    public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
      convertView = inflater.inflate(R.layout.child, null);
      TextView question = (TextView) convertView.findViewById(R.id.nomChild);
      question.setText(getChild(groupPosition, childPosition).toString());
      return convertView;
    }

    public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
      // TextView textView = getGenericView();
      // textView.setText(getGroup(groupPosition).toString());
      convertView = inflater.inflate(R.layout.group, null);
      TextView question = (TextView) convertView.findViewById(R.id.nomGroup);
      question.setText(getGroup(groupPosition).toString());
      return convertView;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
      return true;
    }

    public boolean hasStableIds() {
      return true;
    }
  }
}

问题是我可以正确获取项目,但是当我尝试扩展组时,它不起作用。

任何想法?


编辑:意见

迭代器.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/ExpandableListView"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_gravity="center_vertical"
 >
  </ExpandableListView> 

</LinearLayout>

组.XML

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout
android:id="@+id/widget29"
android:layout_width="305px"
android:layout_height="41px"
android:layout_x="8px"
android:layout_y="29px">
<TextView
android:id="@+id/nomGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
>
</TextView>
<Button
android:id="@+id/widget31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</Button>
</RelativeLayout>
</AbsoluteLayout>

子XML

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout
android:id="@+id/nomChild"
android:layout_width="305px"
android:layout_height="41px"
android:layout_x="8px"
android:layout_y="29px"
>
<TextView
android:id="@+id/widget30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
>
</TextView>
</RelativeLayout>
</AbsoluteLayout>

我们无权访问您的视图,因此我将您的代码更改为使用硬编码的 TextView,它对我来说效果很好。看一下,也许您可​​以发现我们看不到的错误。

public class Main extends Activity {

    class MyExpandableListAdapter extends BaseExpandableListAdapter {

        private String[]        groups  = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
        private String[][]  children    = { { "Arnold", "Barry", "Chuck", "David" },
                                        { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                                        { "Fluffy", "Snuggles" }, { "Goldy", "Bubbles" } };

        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return children[groupPosition].length;
        }

        public View getChildView(int groupPosition,
                int childPosition,
                boolean isLastChild,
                View convertView,
                ViewGroup parent) {

            TextView question = new TextView(Main.this);
            question.setText(getChild(groupPosition, childPosition).toString());
            return question;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            TextView question = new TextView(Main.this);
            question.setText(getGroup(groupPosition).toString());
            return question;
        }

        public boolean hasStableIds() {
            return true;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ExpandableListView lv = new ExpandableListView(this);
        MyExpandableListAdapter questions = new MyExpandableListAdapter();
        lv.setAdapter(questions);

        LinearLayout ll = new LinearLayout(this);
        setContentView(ll);
        ll.addView(lv);

    }

}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ExpandableList View 不展开 的相关文章

随机推荐

  • OpenShift :: POD 不会从部署配置继承“名称标签”

    我从 git repo 基于 Docker 的应用程序 创建了一个构建配置 oc new build
  • Highcharts 热图 - 禁用不同颜色的图例结果

    我正在使用 Highcharts 热图 如果我通过设置禁用图例 legend enabled false 图表中使用的颜色不同 我还提供了一些 colorAxis 信息 例如最小值 最大值和停止点 这里有一个fiddle http jsfi
  • “会话”从哪里来?

    我正在我的 Rails 应用程序中构建一个会话控制器 我只是不确定为什么有些东西在这里工作 在创建和销毁动作中 session index 被分配给 nil 或用户 ID 但这个会话哈希没有在任何地方定义 据我所知 为什么这有效 谁能帮我澄
  • 这个 cronjob 能工作吗?

    我正在尝试设置一个 cronjob 来运行 PHP 文件 我只是想知道我这样做是否正确 假设 php 位于http mysite com myscript cronjob php http mysite com myscript cronj
  • Maven 构建失败 - 找不到插件

    我已经使用 m2 eclipse 工具创建了一个项目 并选择了 Web 应用程序原型 如果我尝试打包这个空应用程序 我会收到构建失败消息 ERROR Plugin org apache maven plugins maven war plu
  • 如何使 group_by 和 lm 更快?

    这是一个样本 df lt tibble subject rep letters 1 7 c 5 6 7 5 2 5 2 day c 3 7 2 7 1 7 3 7 6 7 3 7 6 7 x1 runif 32 x2 rpois 32 3
  • 如何通过 Google App Engine 批量加载程序使用 key_name 上传数据

    我可以上传数据 但 key name 为空 我怎样才能使用 id CSV http en wikipedia org wiki Comma separated values作为数据存储上的 key name 我喜欢使用 id 作为 key
  • 使用sql查询插入器一小时后删除表中的一行

    我有一个表 其中包含一个名为 datetime 的列 其中包含日期和时间 2013 12 26 09 40 41 我想删除一小时前的行 请提出一些查询 这就是我尝试过的 delete from detail1 WHERE datetime
  • 从堆栈安装 ghcjs

    我通过堆栈安装了 GHC 这样stack ghc version显示 GHC 7 10 3 stack install ghcjs Run from outside a project using implicit global proje
  • 是否有用于 Windows 驱动程序开发的开源 C 库(非 c++)? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 是否有用于 Windows 驱动程序开发的开源 C 库 非 c 我正在开发一个网络设备驱动程序 需要一些
  • Powershell 返回错误结果

    我在 Powershell 中遇到了这个奇怪的问题 而不是在其他语言中 谁能向我解释一下为什么会发生这种情况 我尝试返回指定的数字 数字 8 但该函数不断向我抛出所有内容 这是一个错误还是设计使然 Function GetNum Retur
  • 处理两个 != 子句的 OR 语句 Python

    使用Python 2 7 我知道这是非常基本的 但为什么下面的语句不能按书面方式工作 input int raw input while input 10 or input 20 print Incorrect value try agai
  • 如何将 PHP 回溯保存到错误日志中?

    我现在正在使用这个 error log serialize debug backtrace 但我每次都必须反序列化它 有没有更好的方法来存储回溯 这应该生成一个可读的字符串 error log print r debug backtrace
  • .NET for Windows 8 配置文件中的程序集列表

    我正在寻找 NET for Windows 8 配置文件中的程序集列表 这是用于 WIndows 8 Metro 风格应用程序的配置文件 与 Silverlight 一样 它不使用完整的 NET 框架 用于 Metro 风格应用程序的 NE
  • 错误消息“java.net.SocketException:套接字失败:EACCES(权限被拒绝)”

    我收到错误消息 java net SocketException 套接字失败 EACCES 权限被拒绝 当我尝试应用下面的代码时 这是我调用的函数并给了我这个异常 public void run TODO Auto generated me
  • 如何在 ImageMagick 中绘制文本并为其添加阴影?

    我正在图像上打印一些文本convert我想用黑色阴影装饰文本 我尝试过 blur or 高斯但我不能应用于文本 它仅应用于背景图像 我需要使用 draw命令与否 注释 这是我需要更新阴影的代码 font geometricslab703bt
  • Curl 错误 tlsv1 警报协议版本

    以下curl 请求返回错误 有人可以解释一下出了什么问题以及如何纠正它 我已经尝试强制curl使用不同的ssl版本 sslv3和 sslv2 但这不起作用 curl exe GET https www expert nl verbose i
  • 存储波兰语字符 mysql

    我试图保存 等字符 但它们以问号的形式保存在数据库中 我使用 phpMyAdmin 保存它们 数据库和表的排序规则是utf8 bin 尝试将排序规则更改为 utf8 unicode ci or utf8 polish ci 您可以参考 ht
  • Travis-CI中的新作业无法获取curl库

    我已经使用许多 apt get 配置了 Travis CI 并且运行完美 但从本周开始 apt get 失败 部分库无法检索 我没有更改代码 我怎么解决这个问题 有问题的库是curl 工作内容 4天前 https travis ci org
  • ExpandableList View 不展开

    我正在尝试个性化 ExpandableListTview I create Iterator Xml 带有 ExpandableList 视图 group xml 带有简单 TextView 和 Button 的相对布局 Child xml