草庐IT

android - ExpandableListView 没有反应并收到任何点击

coder 2023-12-18 原文

当我尝试将可扩展列表插入现有 Activity (不是从 ExpandalbleListActivity 派生)时,我遇到了几个问题。

该列表确实像我的 XML 布局中描述的那样显示,但是当我尝试单击/展开它时它没有反应。

为了测试,我在列表上方插入了一个按钮,它收到了点击。它自己的列表没有说 clickable=false。

可扩展列表的代码:

<ExpandableListView
android:id="@+id/h_Zzwa_activity_listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:groupIndicator="@color/transparent" android:clickable="true">
</ExpandableListView>

初始化列表的代码:

this.m_adapter = new HZzwaListAdapter(this, m_requests);
    listZzwa =  (ExpandableListView) findViewById(R.id.h_Zzwa_activity_listView);
    listZzwa.setAdapter(this.m_adapter)

适配器(启动并调用组..)

public class HZzwaListAdapter extends BaseExpandableListAdapter
{

private List<HMyMessage> items;
private Context myContext;


public HZzwaListAdapter(Context context)
{
    myContext = context;
}

public HZzwaListAdapter(Context context, List<HMyMessage> items)
{
    myContext = context;
    this.items = items;
}





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

    if (convertView == null)
    {
        LayoutInflater inflater = (LayoutInflater) myContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.h_Zzwa_list_subitem,
                null);
    }

    HMyMessage message = items.get(childPosition);
    if (message != null)
    {
        TextView tvPlayerName = (TextView) convertView
                .findViewById(R.id.h_Zzwalistitem_info_signText);
        tvPlayerName.setText(message.info.getSign());
    }
    return convertView;
}


@Override
public int getChildrenCount(int groupPosition)
{
    return 1;
}


@Override
public Object getGroup(int groupPosition)
{
    return null;
}


@Override
public int getGroupCount()
{
    return items.size();
}


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


@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent)
{

    if (convertView == null)
    {
        LayoutInflater inflater = (LayoutInflater) myContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater
                .inflate(R.layout.h_machching_list_item, null);
    }

    // Get item and set it into the view
    HMyMessage plan = (HMyMessage) items.get(groupPosition);
    if (plan != null)
    {
        TextView pname = (TextView) convertView
                .findViewById(R.id.h_Zzwalistitem_pname);
        TextView pF = (TextView) convertView
                .findViewById(R.id.h_Zzwalistitem_pText);

        if (pname != null)
        {
            pname.setText(plan.requester.getName());
        }
        if (pF != null)
        {
            pF.setText(plan.p + " unit  ");
        }
    }

    return convertView;

}


@Override
public boolean hasStableIds()
{
    return false;
}


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

@Override
public Object getChild(int groupPosition, int childPosition)
{
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getChildId(int groupPosition, int childPosition)
{
    // TODO Auto-generated method stub
    return 0;
}

}

即使我为点击或 listItemClick 事件设置了监听器,也没有任何反应。

为什么?同样的事情对一个普通的列表非常有效:/

谢谢

最佳答案

请添加 child 和组布局。对于 listview,存在一个类似的问题,即 listview 未收到 onItemClick 当 listview 的项目具有按钮时。我之前遇到过这个问题,所以我必须为适配器中的每个项目实现 onclick。检查这个 article ListView doesn’t respond to OnItemClickListenerIssue 3414 ListView doesn't receive OnItemClick/OnItemLongClick for items with clickable or focusable content

编辑:为Button View 或EditText View 放置android:focusable="false"

关于android - ExpandableListView 没有反应并收到任何点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10208666/

有关android - ExpandableListView 没有反应并收到任何点击的更多相关文章

  1. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

  2. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  3. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  4. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  5. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  6. ruby-on-rails - RSpec:避免使用允许接收的任何实例 - 2

    我正在处理旧代码的一部分。beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)endRubocop错误如下:Avoidstubbingusing'allow_any_instance_of'我读到了RuboCop::RSpec:AnyInstance我试着像下面那样改变它。由此beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)end对此:let(:sport_

  7. 没有类的 Ruby 方法? - 2

    大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow

  8. ruby-on-rails - 我更新了 ruby​​ gems,现在到处都收到解析树错误和弃用警告! - 2

    简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und

  9. ruby-on-rails - Rails 3,嵌套资源,没有路由匹配 [PUT] - 2

    我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle

  10. ruby-on-rails - 有没有办法为 CarrierWave/Fog 设置上传进度指示器? - 2

    我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r

随机推荐