如何设置自定义ListAdapter到列表视图中appwidget? [英] How to set custom ListAdapter to list view in appwidget?

查看:136
本文介绍了如何设置自定义ListAdapter到列表视图中appwidget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView。我需要为每个列表项的自定义视图,所以我创建了一个自定义ListAdapter这给意见,布局,这在下面给出。但我怎么设置这个listAdapter在使用RemoteViews该插件的ListView的?

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@机器人:彩色/ background_light
    机器人:layout_margin =1SP
    机器人:填充=10SP
    >

    <的TextView
        机器人:ID =@ + ID / widgetInfo1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=@字符串/ listItemDummy
        机器人:文字颜色=@机器人:彩色/黑白
        />

    <的TextView
        机器人:ID =@ + ID / widgetInfo2
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=@字符串/ listItemDummy
        机器人:文字颜色=@机器人:彩色/黑白
        />

< / LinearLayout中>
 

解决方案

而不是常见的适配器 RemoteViews 你需要实现<一个href="http://developer.android.com/reference/android/widget/RemoteViewsService.RemoteViewsFactory.html"相对=nofollow> RemoteViewsFactory 。要恢复自定义远程视窗的(是的,远程视窗的每个项目,而不是查看),你需要重写它的<一个href="http://developer.android.com/reference/android/widget/RemoteViewsService.RemoteViewsFactory.html#getViewAt%28int%29"相对=nofollow> getViewAt(INT位置) 的方法。

此外,人们只是不 setAdapter()远程视窗 S,则需要提供一个<一个HREF =htt​​p://developer.android.com/reference/android/widget/RemoteViewsService.html相对=nofollow> RemoteViewsService 将返回上述 RemoteViewsFactory 向它的客户。

最后,就是要展示的远程视窗 S中的客户端,你传递一个意图此服务

服务及其意图,你需要在你的manifest文件来声明。这将使您的应用程序一样的看法与其他应用程序或任何远程进程异地签单的供应商。

I have a listView. I needed a custom view for each list item, so I've created a custom ListAdapter which gives the views, layout for which is given below. But how do I set this listAdapter to the ListView in the widget using RemoteViews ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/background_light"
    android:layout_margin="1sp"
    android:padding="10sp"
    >

    <TextView
        android:id="@+id/widgetInfo1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/listItemDummy"
        android:textColor="@android:color/black"
        />

    <TextView
        android:id="@+id/widgetInfo2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/listItemDummy"
        android:textColor="@android:color/black"
        />

</LinearLayout>

解决方案

Instead of the common Adapter, for RemoteViews you need to implement RemoteViewsFactory. To return custom RemoteView's (yes, RemoteView for each item and not View), you will need to override its getViewAt(int position) method.

Also, one just does not setAdapter() for RemoteViews, you would need to provide a RemoteViewsService which will return above RemoteViewsFactory to its clients.

Finally, to the client that is going to show the RemoteViews, you pass an Intent of this service.

The Service and its Intent you will need to declare in your manifest file. This will make your App a provider of remote List like views to other apps or any remote process.

这篇关于如何设置自定义ListAdapter到列表视图中appwidget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆