Saturday, 10 August 2013

Does not change View when the widget clicks

Does not change View when the widget clicks

I have big problem. I program widget with listview (use
RemoteViewsService), there is Activity, which I call(handler on click in
ListView) from WidgetProvider, but I need change View component for click
and it's not works! View of Widget here
public class MainActivity extends Activity {
private int mAppWidgetId = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
String word=getIntent().getStringExtra(TimeWidgetProvider.EXTRA_WORD);
boolean cinnost
=getIntent().getBooleanExtra(TimeWidgetProvider.EXTRA_INDIKATOR,false);
if(word!=null){
Intent i = new Intent(this,Aktivita.class);
startActivity(i);
}
else if(cinnost){
// Getting an instance of WidgetManager
AppWidgetManager appWidgetManager =
AppWidgetManager.getInstance(getBaseContext());
// Instantiating the class RemoteViews with widget_layout
RemoteViews views = new
RemoteViews(getBaseContext().getPackageName(),
R.layout.list_row_layout);
// Setting the ImagetButton prace
views.setImageViewResource(R.id.tlacitko, R.drawable.button_active);
// Tell the AppWidgetManager to perform an update on the app widget
appWidgetManager.updateAppWidget(mAppWidgetId, views); // nothing
change :(
Toast.makeText(this, "Zapl jsi praci", Toast.LENGTH_LONG).show();
}
finish();
}
And there is method from RemoteViewsFactory, where I distinguish the click
on the components(ImageButton - "tlacitko" or TextView -"description")
@Override
public RemoteViews getViewAt(int position) {
RemoteViews row=new RemoteViews(ctxt.getPackageName(),
R.layout.list_row_layout);
row.setTextViewText(R.id.description, items[position]);
row.setLabelFor(R.id.tlacitko, 1);
Intent i=new Intent();
Bundle extras=new Bundle();
extras.putString(TimeWidgetProvider.EXTRA_WORD, items[position]);
i.putExtras(extras);
row.setOnClickFillInIntent(R.id.description, i);
i=new Intent();
extras=new Bundle();
extras.putBoolean(TimeWidgetProvider.EXTRA_INDIKATOR, true);
i.putExtras(extras);
row.setOnClickFillInIntent(R.id.tlacitko, i);
return(row);
}
Thank you for any response!

No comments:

Post a Comment