2014-04-04 67 views

回答

0

@saugat人ligal - 你可以從上面的鏈接給予找到列表視圖演示:

https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget/LoremWidget

而且你可以使用按鈕來同步或刷新你的listview像這樣:

package com.automatic.widget; 

import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.Intent; 
import android.widget.RemoteViews; 

public class Widget extends AppWidgetProvider { 

private static final String SYNC_CLICKED = "automaticWidgetSyncButtonClick"; 

@Override 
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
    RemoteViews remoteViews; 
    ComponentName watchWidget; 

    remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); 
    watchWidget = new ComponentName(context, Widget.class); 

    remoteViews.setOnClickPendingIntent(R.id.sync_button, getPendingSelfIntent(context, SYNC_CLICKED)); 
    appWidgetManager.updateAppWidget(watchWidget, remoteViews); 
} 

@Override 
public void onReceive(Context context, Intent intent) { 
    // TODO Auto-generated method stub 
    super.onReceive(context, intent); 

    if (SYNC_CLICKED.equals(intent.getAction())) { 

     AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 

     RemoteViews remoteViews; 
     ComponentName watchWidget; 

     remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); 
     watchWidget = new ComponentName(context, Widget.class); 

     remoteViews.setTextViewText(R.id.sync_button, "TESTING"); 

     appWidgetManager.updateAppWidget(watchWidget, remoteViews); 

    } 
} 

protected PendingIntent getPendingSelfIntent(Context context, String action) { 
    Intent intent = new Intent(context, getClass()); 
    intent.setAction(action); 
    return PendingIntent.getBroadcast(context, 0, intent, 0); 
} 
} 

所以現在你可以整合它,並刷新ListView的工作......希望這將有助於

相關問題