Android之ListView的个人笔记。(新手必看)

在Android学习中,除了要把握住整个软件代码的整体结构外,我想对于新手来说,方法的参数的具体意义也是一个重要的问题,今天我对有关ListView中使用的方法进行总结“

(1)public<nobr><span class="sympad"><a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context,%20int,%20T%5B%5D)">ArrayAdapter</a></span>(<a href="http://developer.android.com/reference/android/content/Context.html">Context</a> context, int textViewResourceId, T[] objects)</nobr>

<nobr> ~~Context: 表示Android的上下文对象。</nobr>

<nobr> ~~t<span style="font-size:16px; white-space:nowrap">extViewResourceId:表示要使用的布局管理器。</span></nobr>

<nobr><span style="font-size:16px; white-space:nowrap"> <span style="white-space:pre"></span>~~<span style="font-size:16px; white-space:nowrap">T[] objects:要操作的数据内容。</span></span></nobr>

详解:

(1)什么是Context?

Context字面意思是上下文,位于framework package的android.content.Context中,其实该类为LONG型,类似Win32中的Handle句柄。很多方法需要通过 Context才能识别调用者的实例:比如说Toast的第一个参数就是Context,一般在Activity中我们直接用this代替,代表调用者的实例为Activity,而到了一个button的onClick(View view)等方法时,我们用this时就会报错,所以我们可能使用ActivityName.this来解决,主要原因是因为实现Context的类主要有Android特有的几个模型,Activity以及Service。

Context提供了关于应用环境全局信息的接口。它是一个抽象类,它的执行被Android系统所提供。它允许获取以应用为特征的资源和类型。同时启动应用级的操作,如启动Activity,broadcasting和接收intents。

(2)android中自定的布局管理器有哪些,在哪里能够找到?

andorid本身提供了很多布局管理器:

相关的布局管理的具体说明参考文档:http://developer.android.com/reference/android/R.layout.html

监听事件中所使用的OnItemSelectedListener事件也是我们经常用到的,因此我们要覆盖方法

public abstract void onItemSelected (AdapterView<?> parent, View view, int position, long id)
Since: API Level 1

Callback method to be invoked when an item in this view has been selected. This callback is invoked only when the newly selected position is different from the previously selected position or if there was no selected item.

Impelmenters can call getItemAtPosition(position) if they need to access the data associated with the selected item.

鉴于此项目已被选定时,被调用的回调方法。只有当新选定的位置从先前选定的位置是不同的,如果没有选定的项目,这个回调函数被调用。
impelmenters可致电getItemAtPosition(位置),如果他们需要访问与所选项目相关的数据。

Parameters
parent The AdapterView where the selection happened(选择发生的AdapterView
view The view within the AdapterView that was clicked(View被点击AdapterView
position The position of the view in the adapter(适配器中点击viewd的位置)
id The row id of the item that is selected (选定行目的ID)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值