0

My widget is retriving last 5 posts from RSS. User can click widget to refresh data and can click arrows (next/prev) to navigate through posts.

I try to make widget with shared preferences. Everything I working fine unitl I add second instance of the same widget. Then second one override first settings. I try to make something like this:

(Configure widget activity):

public static String PREFS_NAME = "my_name" + ID_WIDGET;

or

editor.putString("login_" + mAppWidgetId, _loginEdit.getText().toString());

But I have problem with retrive this data - I can't retrive widget id. I tried many solutions but none of them work for me.

ComponentName name = new ComponentName(contextApp, TweetWidget.class);
int [] ids = AppWidgetManager.getInstance(contextApp).getAppWidgetIds(name);

Here I have ids but I need widget id which one was clicked by user - update information in the widget. Anyone have working solution?

MicNeo
  • 716
  • 3
  • 12
  • 20
  • have you considered making a HashTable to map index to WidgetInstance? – hovanessyan Jan 22 '12 at 13:32
  • Well, problem is that I don't know how to extract id of widget which was clicked by user. So making a HashTable won't help me, because I still won't get it. – MicNeo Jan 22 '12 at 18:26
  • This will probably work only if you have a finite amount of instances. When you create your instances you should use setId() and assign positive numbers:1,2,3. Your widget should extend View and implement OnClickListener. Than in overriding the onClick method, you can use "switch (v.getId()) --> case R.id.1, case R.id.2 etc. This is not very dynamic though. – hovanessyan Jan 22 '12 at 19:13
  • Widget have to extend AppWidgetProvider, isn't it? If I could link widget id with its instance. Here is some kind of solution but I don't really know how to apply it to my project: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget – MicNeo Jan 28 '12 at 10:17

0 Answers0