`
dowhathowtodo
  • 浏览: 775290 次
文章分类
社区版块
存档分类
最新评论

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)

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 view position id
The AdapterView where the selection happened(选择发生AdapterView
The view within the AdapterView that was clicked(View被点击AdapterView
The position of the view in the adapter(适配器中点击viewd的位置)
The row id of the item that is selected (选定行目的ID)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics