我一直在努力让我的光标在 ListView 中正确显示。 它在使用 toast 时正确显示,因此光标可以正确检索数据,但我无法使其以列表格式显示。
每行应该有 6 列。
它只显示一行,没有数据。 我敢肯定这是一个非常基本的问题。 也许有人可以告诉我哪里出错了,我将不胜感激。
显示光标.Java
public class DisplayCursor extends ListActivity
{
MyDBManager db = new MyDBManager(this);
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_cursor);
db.open();
Cursor cursor = db.getAllRows();
startManagingCursor(cursor);
String[] columns = new String[] { MyDBManager.KEY_DESCRIPTION, MyDBManager.KEY_PERCENTAGE, MyDBManager.KEY_PRICE,
MyDBManager.KEY_VOLUME, MyDBManager.KEY_VFM, MyDBManager.KEY_QUANTITY };
int[] to = new int[] { R.id.description,R.id.perc,R.id.price,R.id.units,R.id.vol, R.id.vfm };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor, columns, to);
this.setListAdapter(mAdapter);
db.close();
}
}
行.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/description"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="27dp" />
<TextView
android:id="@+id/vol"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/description"
android:layout_alignBottom="@+id/description"
android:layout_toRightOf="@+id/description" />
<TextView
android:id="@+id/perc"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/vol"
android:layout_alignBottom="@+id/vol"
android:layout_toRightOf="@+id/vol" />
<TextView
android:id="@+id/price"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/perc"
android:layout_alignBottom="@+id/perc"
android:layout_toRightOf="@+id/perc" />
<TextView
android:id="@+id/units"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/price"
android:layout_alignBottom="@+id/price"
android:layout_toRightOf="@+id/price" />
<TextView
android:id="@+id/vfm"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/units"
android:layout_alignBottom="@+id/units"
android:layout_toRightOf="@+id/units" />
</RelativeLayout>
activity_display_cursor.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nodata"/>
</LinearLayout>
最佳答案
啊,带有 CursorAdapter 的 ListView 又来袭了!第一次 grok 并不容易,所以:
您的大部分内容都是正确的,但是,您的 row.xml 需要为要显示的光标中的每一列包含一个 View 。 CursorAdapter 构造函数中的“layout”参数指定布局文件的 resID;此文件描述一行。在您的情况下,您可能想要一个包含 6 个 TextView 的 RelativeLayout,每个 R.id 值对应一个 构造函数的“to”参数。 CursorAdapter 负责将游标列映射到“to”参数中的 View ,这就是为什么这些数组的大小必须相同。
activity_display_cursor.xml 布局定义了 ListView。
请注意,我不经常使用 ListActivity。在常规 Activity 中设置带有适配器的 ListView 非常容易。此外,startManagingCursor 在 API 11 中已弃用。更好的选择是使用 android.support.v4.content.CursorLoader 和 android.support.v4.widget.SimpleCursorAdapter。
关于Android - 在 ListView 中显示来自数据库的游标结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367721/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
导读语言模型给我们的生产生活带来了极大便利,但同时不少人也利用他们从事作弊工作。如何规避这些难辨真伪的文字所产生的负面影响也成为一大难题。在3月9日智源Live第33期活动「DetectGPT:判断文本是否为机器生成的工具」中,主讲人Eric为我们讲解了DetectGPT工作背后的思路——一种基于概率曲率检测的用于检测模型生成文本的工具,它可以帮助我们更好地分辨文章的来源和可信度,对保护信息真实、防止欺诈等方面具有重要意义。本次报告主要围绕其功能,实现和效果等展开。(文末点击“阅读原文”,查看活动回放。)Ericmitchell斯坦福大学计算机系四年级博士生,由ChelseaFinn和Chri
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi