ListView里面如何获取Spinner对象.

_真真 2012-12-02 10:16:31
大侠们好,
现在我的Activity中的用的是这个布局,里面有个ListView
这个是listview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/MyListView"
/>
</LinearLayout>

我的ListView中的ListItem用的另外一个布局
这个是listitem_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
>

<TextView
android:id="@+id/txtTitle"
android:layout_width="80dp"
android:layout_height="wrap_content"
/>

<Spinner
android:id="@+id/MySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>

我的Activity用的是最上面listview_layout.xml布局,
我的Activity中 用SimpleAdapter引用了listitem_layout.xml布局

问题:

我现在想在ListView的Activity里面获取到listview_layout.xm布局中的Spinner控件ID
怎么获取?
直接在ListView的 Activity中 findViewById(MySpinner) 会报空指针异常,找不到.
因为Activity中的布局文件用的是listview_layout.xml的,
而Spinner控件在这个listitem_layout.xml这个里面.

我是新手 大虾帮忙啊 赶紧不尽
...全文
311 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
_真真 2012-12-10
  • 打赏
  • 举报
回复
谢谢大家 是的. 要在自定义的 Adapter的 getView里面写.
问答小助手 2012-12-04
  • 打赏
  • 举报
回复
你不能直接使用 findViewById(spinnerId)。你应该重写Custom Adapter中的getView()方法,而不是Simple Adapter里面的方法。在这个方法里inflate listitem_layout到一个view(v),然后使用 v.findViewById(spinnerId). 看这个链接,可以帮助你创建custom adapter。例子中ImageView对象是在GetView方法中创建的。
android_Y 2012-12-03
  • 打赏
  • 举报
回复
要用自定义ListView
lenghucs 2012-12-03
  • 打赏
  • 举报
回复
写个内部类的adapter里面不就可以view.findViewById()了 这样行不?同是新手的回答
stormier 2012-12-03
  • 打赏
  • 举报
回复
引用 1 楼 lenghucs 的回复:
写个内部类的adapter里面不就可以view.findViewById()了 这样行不?同是新手的回答
我看行
laoyang_113 2012-12-03
  • 打赏
  • 举报
回复
要在adapter中getview方法中写,

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧