如何设置自定义ListAdapter到列表视图中appwidget?自定义、视图、如何设置、列表

2023-09-07 15:23:14 作者:喂不饱的孤独

我有一个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 你需要实现 RemoteViewsFactory 。要恢复自定义远程视窗的(是的,远程视窗的每个项目,而不是查看),你需要重写它的 getViewAt(INT位置) 的方法。

此外,人们只是不 setAdapter()远程视窗 S,则需要提供一个 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>
excel 自定义设置单元格格式,前面设好固定数值后,在表格上输出8个数字,与自定义设置中间有空格,

解决方案

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.