从J2EE转向Android的第七天-----文件管理

本文详细解析了Android开发中ListActivity与ListView的绑定机制,包括常见错误及解决方法,对比了不同ID引用的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       先说说昨天的错误:

       异常信息:java.lang.RuntimeException: Your content must have a ListView whose id  attribute is 'android.R.id.list'

       还是看API吧,API中这样描述:

       An activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item.

       ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results. Binding, screen layout, and row layout are discussed in the following sections

      ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)

 

       ListActivity是一个显示数据的Activity,拥有一个listview对象用来实现数据源的绑定显示

       ListActivity本身有一个默认的layout,其中包含一个全屏的list,如果使用默认的layout,则不适用setContentView方法,否则就自己建一个layout,使用setConvtentView()加载.

      说下我出错的地方,layout必须有一个ListView,在我的layout中有个id为 @+id/list的ListView,但是需要的是@android:id/list的ListView.

      但是@id+/list 和@android:id/list有什么区别呢?

      在网上转了半天,的出的结论是:

             @+id/list,会新建一个list;

             @android:id/list是引用已经定义好的list,其实系统内部已经定义好了一个list

     照着书上做了个例子。

           onFocusChange,此事件在电脑pc上是鼠标滚动或按键触发,哈哈,我没android手机,悲剧,穷人啊。

     为了手机奋斗。奋斗也要睡觉。睡觉。

 

         

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值