jjzjj

java - GridView OnItemClickListener 没有调用 onItemClick

coder 2023-12-19 原文

我正在尝试为我的 Gridview 中的项目设置一个 OnItemClickListener。由于某种原因,永远不会调用监听器中的 onItemCLick 方法。

设置监听器和适配器:

UsersAdapter usersAdapter = new UsersAdapter(venueUsers);
gridView.setAdapter(usersAdapter);
gridView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        Intent intent = new Intent(Users.this, com.roqbot.client.login.Profile.class);
        intent.putExtra("idUser", id);
        startActivity(intent);
    }
});

我的适配器:

private class UsersAdapter extends BaseAdapter implements ListAdapter {
    private JSONArray users;

    private UsersAdapter(JSONArray users) {
        this.users = users;
    }

    public int getCount() {
        return users.length();
    }

    public JSONObject getItem(int position) {
        return users.optJSONObject(position);
    }

    public long getItemId(int position) {
        return users.optJSONObject(position).optInt("idUser");
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = Users.this.getLayoutInflater().inflate(R.layout.user_icon, null);

        JSONObject user = getItem(position);

        TextView username = (TextView) convertView.findViewById(R.id.username);
        username.setText(user.optString("sName"));

        TextView userScore = (TextView) convertView.findViewById(R.id.userScore);
        int iDJScore = user.optInt("iDJScore");
        if (iDJScore > 0) {
            userScore.setText(Integer.toString(iDJScore));
        }
        else {
            userScore.setVisibility(TextView.INVISIBLE);
            ((ImageView) convertView.findViewById(R.id.userScoreBg)).setVisibility(View.INVISIBLE);
        }

        TextView userLevel = (TextView) convertView.findViewById(R.id.userLevel);
        userLevel.setText(user.optString("iDJLevel"));

        TextView userMatch = (TextView) convertView.findViewById(R.id.userMatch);
        ImageView matchIcon = (ImageView) convertView.findViewById(R.id.matchIcon);
        int iCompatibility = user.optInt("iCompatibility");
        if (iCompatibility != 0) {
            userMatch.setText( iCompatibility + "%");
        }
        else {
            userMatch.setVisibility(TextView.INVISIBLE);
            matchIcon.setVisibility(ImageView.INVISIBLE);
        }

        ImageView userIcon = (ImageView) convertView.findViewById(R.id.userIcon);
        String sUserIcon = user.optString("sImageUrl-thumb");
        imageLoader.DisplayImage(sUserIcon, Users.this, userIcon);

        return convertView;
    }
}

我对为什么点击监听器不工作感到很困惑。这段代码对我来说在很多其他地方都有效。

最佳答案

我遇到了同样的问题。

在我的情况下,“android:focusable = true”阻止项目点击事件

在我的 GridList 项目布局中

<TextView android:id="@+id/auction_item_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:singleLine="true"
    ***android:focusable="true"***
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
/>

我删除了 [android:focusable="true"],问题解决了

关于java - GridView OnItemClickListener 没有调用 onItemClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8410490/

有关java - GridView OnItemClickListener 没有调用 onItemClick的更多相关文章

  1. 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/

  2. 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(

  3. 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

  4. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  5. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  6. c# - 如何在 ruby​​ 中调用 C# dll? - 2

    如何在ruby​​中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL

  7. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  8. ruby - 调用其他方法的 TDD 方法的正确方法 - 2

    我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent

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

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

  10. 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

随机推荐