开发者

App with widget accesing to database

I trying to make my widget get content form database, but its not working :/ And I dont really get it what's wrong

public class Widget extends AppWidgetProvider {   
 private databaseHelper dbHelper;
 SQLiteDatabase db = dbHelper.getReadableDatabase();
 @Override 
 public void onUpdate(Context context, AppWidget开发者_开发技巧Manager appWidgetManager, int[] appWidgetIds)     { 
                    Cursor cursor = db.rawQuery("SELECT column01 FROM my_table WHERE column02=1", null);
                    cursor.moveToPosition(0);
                     String str0 = cursor.getString(0);
                     RemoteViews updateViews = new RemoteViews( 
                    context.getPackageName(),R.layout.widget); 
             updateViews.setTextViewText(R.id.text, str0); 
             appWidgetManager.updateAppWidget(appWidgetIds, updateViews); 
         } 
     } 


You haven't said what part "isn't working", but you are passing the wrong value into updateAppWidget. Replace this:

appWidgetManager.updateAppWidget(appWidgetIds, updateViews);

with this:

for (int i=0;i<appWidgetIds.length;i++){
    appWidgetManager.updateAppWidget(appWidgetIds[i], updateViews);
}

You are passing an array of ints, when you need to pass each array element individually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜