I am trying to make dynamic listview
in widget with help of remoteview
, as I wanted this listview
of application icons in a widget. I want to show incoming notifications from all apps which are separated application wise. I want to create standing notification list and when user clicks on application icon from listview, that particular notification will be displayed. I am using API 19
for getting all notification and also succeeded but I don't know how I can create Listview
in widget with Remoteview
and also with drawables(Icons)
.
Asked
Active
Viewed 5,029 times
7

kiturk3
- 549
- 10
- 30
-
Have you done any code yet? – Apurva Feb 12 '15 at 07:55
-
Any?? A lot code and java files i have tried... – kiturk3 Feb 12 '15 at 09:11
-
Here's another useful answer: http://www.stackoverflow.com/a/6093753/2180161 - it was easier for me to understand this one – maysi Jul 29 '15 at 21:01
2 Answers
6
Have you search or try with other examples having ListView in widget? Please check the Weather Widget demo available on github.
Code:
public class MyWidgetProvider extends AppWidgetProvider {
private static HandlerThread sWorkerThread;
private static Handler sWorkerQueue;
public MyWidgetProvider() {
// Start the worker thread
sWorkerThread = new HandlerThread("MyWidgetProvider-worker");
sWorkerThread.start();
sWorkerQueue = new Handler(sWorkerThread.getLooper());
}
public void onUpdate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; ++i) {
...
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
views.setRemoteAdapter(R.id.lvWidget, svcIntent);
sWorkerQueue.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
views.setScrollPosition(R.id.list, 3);
appWidgetManager.partiallyUpdateAppWidget(appWidgetIds[i], views);
}
}, 1000);
appWidgetManager.updateAppWidget(appWidgetIds[i], views);
...
}
}
}
Which will behave like below:
Please check the github project and above sample code.

halfer
- 19,824
- 17
- 99
- 186

Shreyash Mahajan
- 23,386
- 35
- 116
- 188
-
@kiturk3 Please let me know if this answer not resolved your question or please accept it as right one so that other can also come to know about that and have right direction to their implementation. Thanks. – Shreyash Mahajan Feb 12 '15 at 05:59
-
Actually i wanted to do this for samsung galaxy note edge panel. I had already read your same nswer in another question but that did't work exactly. I had to tweak something extra but it was sure helpful. Thank you :) – kiturk3 Feb 12 '15 at 09:10
-
with help of cade i answered, it gives me listview and that's exactly 70% i needed. Only i have to implement onclickpendingintent event into that. – kiturk3 Feb 12 '15 at 10:48
-
ok. So where is the issue with that? You can send bundle with the onclicklistener that which item you have clicked. As per that you can also handled the action you want. – Shreyash Mahajan Feb 12 '15 at 12:13
-
Here's another useful answer: http://stackoverflow.com/a/6093753/2180161 - it was easier for me to understand this one – maysi Jul 29 '15 at 21:01
1
I had already tried from @iDroid Explorer's solution from one of his previous answers. But listview was not showing up in edge panel(PS: I wanted this to implement in galaxy note edge's panel ).
So i tried below code:
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;
}
And in myService class i have populated required items in list.
I got help from an example called: WidgetListView1, which i found from random searches.

Shreyash Mahajan
- 23,386
- 35
- 116
- 188

kiturk3
- 549
- 10
- 30