Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used the following to add items to my widget as as sample:</p> <pre><code> for(Server srv:mylist){ newView = new RemoteViews(context.getPackageName(), R.layout.widget_row); newView.setTextViewText(R.id.servername,srv.getServerName()); newView.setTextViewText(R.id.serverstatus,srv.getServerStatus()); remoteViews.addView(R.id.widget,newView); } </code></pre> <p>this basically adds a "row" <code>newView</code> to the <code>remoteViews</code></p> <p>edit:</p> <p>Running widget on 2.2. The widget can be stretched depending on your launcher of course.</p> <p>EDIT: </p> <p>try and use the following in the onUpdate()</p> <hr> <pre><code> ComponentName thisWidget = new ComponentName(context, MyWidget.class); Item[] iii = items.getItemsArray(); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widgetlayout); for (Item item : iii) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.row); views.setTextViewText(R.id.textViewShortName, item.title); views.setTextViewText(R.id.textViewDesc, item.description); views.setTextViewText(R.id.textViewDue, new StringBuilder() .append(item.dueDate).toString()); rv.addView(R.id.llWidget, views); } appWidgetManager.updateAppWidget(thisWidget, rv); </code></pre> <p>I still dont understand what's the point in this </p> <pre><code> for (int i = 0; i &lt; N; i++) { int appWidgetId = appWidgetIds[i]; </code></pre> <p>WORKING EXAMPLE: you might still want to implement a service</p> <hr> <pre><code>public class StatusWidget extends AppWidgetProvider { LayoutInflater inflater; int[] appWidgetIds; AppWidgetManager appWidgetManager; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { this.appWidgetIds=appWidgetIds; this.appWidgetManager=appWidgetManager; Timer timer = new Timer(); timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 30000); //30 seconds timeout } @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[]{appWidgetId}); } } else { super.onReceive(context, intent); } } private class MyTime extends TimerTask { RemoteViews remoteViews; AppWidgetManager appWidgetManager; ComponentName thisWidget; Context context; public MyTime(Context context, AppWidgetManager appWidgetManager) { this.context = context; this.appWidgetManager = appWidgetManager; remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_message); thisWidget = new ComponentName(context, StatusWidget.class); } @Override public void run() { remoteViews.removeAllViews(R.id.widget); Date date = new Date(); DateFormat format = SimpleDateFormat.getTimeInstance( SimpleDateFormat.LONG, Locale.getDefault()); InputStream is = null; ImageAdapter myServers =null; List&lt;Server&gt; mylist =null; try { is = new ByteArrayInputStream(Utils.fetch("http://mystatusserver/status", null).toByteArray()); } catch (Exception cte) { } try { String l = Utils.readInputStream(is); List&lt;Server&gt; list= Utils.parseServers(l); mylist= Utils.loadMyServerList(context, list); } catch (Exception e) { e.printStackTrace(); } RemoteViews newView =null; for(Server srv:mylist){ newView = new RemoteViews(context.getPackageName(), R.layout.widget_row); newView.setTextViewText(R.id.servername,srv.getServerName()); newView.setTextViewText(R.id.serverstatus,srv.getServerStatus()); remoteViews.addView(R.id.widget,newView); } newView = new RemoteViews(context.getPackageName(), R.layout.datetime); newView.setTextViewText(R.id.time,"Last Updated At: "+format.format(date)); remoteViews.addView(R.id.widget,newView); appWidgetManager.updateAppWidget(thisWidget, remoteViews); } } } </code></pre> <hr> <p>hope it helps abit</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload