Android 如何借助remoteview创建Listview?

Android 如何借助remoteview创建Listview?,android,listview,notifications,remoteview,Android,Listview,Notifications,Remoteview,我正试图借助于remoteview,在小部件中创建动态listview,因为我想在小部件中创建应用程序图标的listview。我想显示来自所有应用程序的传入通知,这些应用程序是分开的。我想创建一个固定的通知列表,当用户从listview中单击应用程序图标时,将显示特定的通知。我正在使用API19获取所有通知,并且也成功了,但我不知道如何使用Remoteview和drawables(Icons)在小部件中创建Listview? 请查看github上提供的 代码: 公共类MyWidgetProvid

我正试图借助于
remoteview
,在小部件中创建动态
listview
,因为我想在小部件中创建应用程序图标的
listview
。我想显示来自所有应用程序的传入通知,这些应用程序是分开的。我想创建一个固定的通知列表,当用户从listview中单击应用程序图标时,将显示特定的通知。我正在使用
API19
获取所有通知,并且也成功了,但我不知道如何使用
Remoteview
drawables(Icons)

在小部件中创建
Listview
? 请查看github上提供的

代码:

公共类MyWidgetProvider扩展了AppWidgetProvider{
私有静态HandlerThread;
专用静态处理程序队列;
公共MyWidgetProvider(){
//启动辅助线程
sWorkerThread=新HandlerThread(“MyWidgetProvider工作者”);
sWorkerThread.start();
sWorkerQueue=新处理程序(sWorkerThread.getLooper());
}
public void onUpdate(上下文上下文,最终AppWidgetManager AppWidgetManager,int[]AppWidgetId){
对于(int i=0;i
其行为如下所示:


请检查github项目和上面的示例代码。

我已经从@iDroid Explorer的解决方案中尝试了他以前的一个答案。但listview并没有出现在edge面板中(PS:我想在GalaxyNoteEdge的面板中实现这个功能)

所以我尝试了以下代码:

    private RemoteViews updateWidgetListView(Context arg0, int i) {

        //which layout to show on widget
        RemoteViews remoteViews = new RemoteViews(arg0.getPackageName(),
                R.layout.activity_main_sub);

        //RemoteViews Service needed to provide adapter for ListView
        Log.d("fff", "updateWidget: "+ i);

        Intent svcIntent = new Intent(arg0, MyService.class);

        //passing app widget id to that RemoteViews Service
        svcIntent.putExtra("Id", i);
        Log.d("fff", "receiver:"+appnM);
        svcIntent.putExtra("appname", appnM);
        //setting a unique Uri to the intent
        //don't know its purpose to me right now
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
        //setting adapter to listview of the widget

        remoteViews.setRemoteAdapter(i, R.id.list_icon,svcIntent);

//      remoteViews.setRemoteAdapter(i, svcIntent);

        arg0.startService(svcIntent);
        //setting an empty view in case of no data
        remoteViews.setEmptyView(R.id.list_icon, R.id.empty_view);

        Log.d("fff","end of myReceiver");
        return remoteViews;
    }
在myService类中,我填充了列表中的必需项


我从一个名为:WidgetListView1的示例中获得了帮助,我从随机搜索中找到了该示例。

@kiturk3如果此答案没有解决您的问题,请告诉我,或者请接受它作为正确答案,以便其他人也可以了解这一点,并对其实现有正确的方向。谢谢。实际上我想为三星galaxy note边缘面板做这个。我已经在另一个问题中读到了你的答案,但那并不完全有效。我不得不调整一些额外的东西,但它肯定是有用的。谢谢:)在凯德的帮助下,我回答说,它给了我listview,这正是我所需要的70%。只有我必须将onClickPendingEvent事件实现到该事件中。好的。那么问题在哪里呢?您可以使用onclicklistener发送您已单击的项的捆绑包。根据这一点,你也可以处理你想要的操作。这里有另一个有用的答案:-这对我来说更容易理解这一个你做了任何代码吗?有吗??我尝试了很多代码和java文件……这里有另一个有用的答案:-这对我来说更容易理解
    private RemoteViews updateWidgetListView(Context arg0, int i) {

        //which layout to show on widget
        RemoteViews remoteViews = new RemoteViews(arg0.getPackageName(),
                R.layout.activity_main_sub);

        //RemoteViews Service needed to provide adapter for ListView
        Log.d("fff", "updateWidget: "+ i);

        Intent svcIntent = new Intent(arg0, MyService.class);

        //passing app widget id to that RemoteViews Service
        svcIntent.putExtra("Id", i);
        Log.d("fff", "receiver:"+appnM);
        svcIntent.putExtra("appname", appnM);
        //setting a unique Uri to the intent
        //don't know its purpose to me right now
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
        //setting adapter to listview of the widget

        remoteViews.setRemoteAdapter(i, R.id.list_icon,svcIntent);

//      remoteViews.setRemoteAdapter(i, svcIntent);

        arg0.startService(svcIntent);
        //setting an empty view in case of no data
        remoteViews.setEmptyView(R.id.list_icon, R.id.empty_view);

        Log.d("fff","end of myReceiver");
        return remoteViews;
    }