android-使用自定义cursoradapter的listview中的隐藏字段 [英] android - hidden field in listview, using custom cursoradapter

查看:56
本文介绍了android-使用自定义cursoradapter的listview中的隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个列表视图,当您单击一个项目时,我希望对话框片段出现并带有详细信息.使用自定义的cursoradapter填充listview,并且每一行都是从relativelayout扩展的视图.

In my app I have a listview, which when you click on an item i want a dialogfragment to appear with details in it. The listview is populated using a custom cursoradapter and each row is a view extended from a relativelayout.

我的想法是,我将在自定义视图中具有某种id值,并且在选择该ID时,将在新的数据库查询中使用该id来填充dialogfragment.但是,我不希望该行显示该ID,而是将其隐藏.

My thought process is that i would have some kind of id value in the custom view and when selected, the id is used in a new db query to populate the dialogfragment. However, I don't want the id on view in the row, I want it hidden.

我正在考虑创建一个从relativelayout扩展的自定义视图类,并且该视图中的字段将包含ID和两个textview.

I'm thinking that i create a custom view class, extended from relativelayout, and in the view is a field that will hold the id as well as the two textviews.

我的主要问题是研究如何在适配器内使用我的自定义视图.我发现的每个示例都会在newview内增加一个xml布局,但我的xml布局将不包含id字段.

My main problem is working out how to use my custom view inside the adapter. Every example i have found, inflates an xml layout inside newview, but my xml layout will not include the id field.

我可以在newview内为视图创建一个新对象,而不是将xml夸大吗?

Can I just create a new object for my view, inside newview rather than inflating an xml?

或者我缺少明显的东西吗?

Or am I missing something obvious?

谢谢

推荐答案

onItemClick(AdapterView<?>父级中使用 CursorAdapter 时,查看视图,int位置,长id) AdapterView.OnItemClickListener 实现,您可以获得:

When you are working with CursorAdapter in onItemClick(AdapterView<?> parent, View view, int position, long id) implementation of AdapterView.OnItemClickListener you can get:

  1. 基础游标中的 _id 列-简单来说,它是此函数的 long id 参数
  2. 在项目视图中可见或不可见但存在于Cursor中的任何列,方法是将项目投射到Cursor的位置,例如:

  1. the _id column from the underlying Cursor - simply, it is the long id parameter of this function
  2. any column visible or not in your item view but existing in the Cursor by casting the item at position to the Cursor like:

光标c =(光标)parent.getItemAtPosition(位置);

现在 c 指向选定的行,因此您可以从中获取任何列,就像 var value = c.getInt/String/etc(c.getColumnIndex("columnname));

Now c is pointing to the selected row so you are can get any column from it as simple as var value = c.getInt/String/etc(c.getColumnIndex("columnname"));

这篇关于android-使用自定义cursoradapter的listview中的隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆