, .
, appWidgetId. , - HashMap , :
private static class MyValues{
private final int iPicNum = 0;
private final boolean bClosed = false;
public MyValues(int iPicNum, boolean bClosed) {
this.iPicNum = iPicNum;
this.bClosed = bClosed;
}
public int getiPicNum() {
return iPicNum;
}
public boolean isbClosed() {
return bClosed;
}
}
AppWidgetProvider:
private static HashMap<int,MyValues> mValues = new HashMap<int,MyValues>;
:
mValues.put(appWidetId, new MyValues(iPicNum,bClosed);
:
MyValues values = mValues.get(appWidgetId);
if (values != null){
int iPicNum = values.getiPicNum();
boolean bClosed = values.isbClosed();
}
And don't forget to clear the unused data in the onDeleted () method (it is called when a single action of the widget is removed from the screen):
public void onDeleted(Context context, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
if (appWidgetId != -1) {
mValues.remove(appWidgetId);
}
}
}
Hope this helps.
source
share