Frage

I'm trying to get click event on my ListView on homesreen widget. For this I'm using following code:

public class ViewFactory implements RemoteViewsService.RemoteViewsFactory {
...

  @Override
    public RemoteViews getViewAt(int position) {
         RemoteViews row=new RemoteViews(ctxt.getPackageName(),
                R.layout.row);
        Log.i("position receive trans", Integer.toString(position));

        row.setTextViewText(android.R.id.text1, items[position]);
        Intent i = new Intent(this.ctxt, AppWidget.class);
        i.setAction(ACTION_WIDGET_UPDATE_POSITION);
        i.putExtra("position", position);
        row.setOnClickFillInIntent(android.R.id.text1, i);
        return(row);
    }

But I'm getting this event not only after clicking on widget. I'm getting this also after adding widget to the home screen.

Is there any way to determine different actions (Click and adding to homescreen?)

War es hilfreich?

Lösung

Such situation can be determined by
intent.getAction();
For enabling widget is : android.appwidget.action.APPWIDGET_ENABLED
For updatewidget is : android.appwidget.action.APPWIDGET_UPDATE

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top